Merge branch 'devel' of dev.sourcefabric.org:airtime into devel
This commit is contained in:
commit
e5de4f560d
7 changed files with 154 additions and 104 deletions
|
@ -29,4 +29,29 @@ class Application_Common_Database
|
||||||
}
|
}
|
||||||
return $rows;
|
return $rows;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
Wrapper around prepareAndExecute that allows you to use multipe :xx's
|
||||||
|
in one query. Transforms $sql to :xx1, :xx2, ....
|
||||||
|
*/
|
||||||
|
public static function smartPrepareAndExecute($sql, array $params,
|
||||||
|
$type='all', $fetchType=PDO::FETCH_ASSOC)
|
||||||
|
{
|
||||||
|
$new_params = array();
|
||||||
|
$new_sql = $sql;
|
||||||
|
foreach ($params as $k => $v) {
|
||||||
|
$matches_count = substr_count($sql, $k);
|
||||||
|
if ($matches_count == 0) {
|
||||||
|
throw new Exception("Argument $k is not inside $sql");
|
||||||
|
} elseif ($matches_count == 1) {
|
||||||
|
$new_params[$k] = $new_params[$v];
|
||||||
|
} else {
|
||||||
|
foreach ( range(1,$matches_count) as $i ) {
|
||||||
|
preg_replace( "/$k(\D)/", "$k.$i${1}", $sql, 1);
|
||||||
|
$new_params[ $k.$i ] = $v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Application_Common_Database::prepareAndExecute( $new_sql,
|
||||||
|
$new_params, $type, $fetchType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1176,6 +1176,8 @@ SQL;
|
||||||
->delete();
|
->delete();
|
||||||
}
|
}
|
||||||
//adding rows to cc_show_rebroadcast
|
//adding rows to cc_show_rebroadcast
|
||||||
|
/* TODO: Document magic constant 10 and define it properly somewhere
|
||||||
|
--RG */
|
||||||
if (($isRecorded && $data['add_show_rebroadcast']) && ($repeatType != -1)) {
|
if (($isRecorded && $data['add_show_rebroadcast']) && ($repeatType != -1)) {
|
||||||
for ($i=1; $i<=10; $i++) {
|
for ($i=1; $i<=10; $i++) {
|
||||||
if ($data['add_show_rebroadcast_date_'.$i]) {
|
if ($data['add_show_rebroadcast_date_'.$i]) {
|
||||||
|
@ -1189,10 +1191,21 @@ SQL;
|
||||||
} elseif ($isRecorded && $data['add_show_rebroadcast'] && ($repeatType == -1)) {
|
} elseif ($isRecorded && $data['add_show_rebroadcast'] && ($repeatType == -1)) {
|
||||||
for ($i=1; $i<=10; $i++) {
|
for ($i=1; $i<=10; $i++) {
|
||||||
if ($data['add_show_rebroadcast_date_absolute_'.$i]) {
|
if ($data['add_show_rebroadcast_date_absolute_'.$i]) {
|
||||||
$con = Propel::getConnection(CcShowPeer::DATABASE_NAME);
|
//$con = Propel::getConnection(CcShowPeer::DATABASE_NAME);
|
||||||
$sql = "SELECT date '{$data['add_show_rebroadcast_date_absolute_'.$i]}' - date '{$data['add_show_start_date']}' ";
|
//$sql = "SELECT date '{$data['add_show_rebroadcast_date_absolute_'.$i]}' - date '{$data['add_show_start_date']}' ";
|
||||||
$r = $con->query($sql);
|
$sql = <<<SQL
|
||||||
$offset_days = $r->fetchColumn(0);
|
SELECT date :rebroadcast - date :start
|
||||||
|
SQL;
|
||||||
|
$offset_days =
|
||||||
|
Application_Common_Database::prepareAndExecute($sql,
|
||||||
|
array(
|
||||||
|
'rebroadcast' =>
|
||||||
|
$date["add_show_rebroadcast_date_absolute_$i"],
|
||||||
|
'start' =>
|
||||||
|
$date['add_show_start_date']), "column" );
|
||||||
|
|
||||||
|
//$r = $con->query($sql);
|
||||||
|
//$offset_days = $r->fetchColumn(0);
|
||||||
|
|
||||||
$showRebroad = new CcShowRebroadcast();
|
$showRebroad = new CcShowRebroadcast();
|
||||||
$showRebroad->setDbDayOffset($offset_days." days");
|
$showRebroad->setDbDayOffset($offset_days." days");
|
||||||
|
@ -1630,7 +1643,7 @@ SQL;
|
||||||
$start_string = $start_timestamp->format("Y-m-d H:i:s");
|
$start_string = $start_timestamp->format("Y-m-d H:i:s");
|
||||||
$end_string = $end_timestamp->format("Y-m-d H:i:s");
|
$end_string = $end_timestamp->format("Y-m-d H:i:s");
|
||||||
if ($onlyRecord) {
|
if ($onlyRecord) {
|
||||||
$sql .= " AND (si1.starts >= :start::TIMESTAMP AND si1.starts < timestamp :end::TIMESTAMP)";
|
$sql .= " AND (si1.starts >= :start::TIMESTAMP AND si1.starts < :end::TIMESTAMP)";
|
||||||
$sql .= " AND (si1.record = 1)";
|
$sql .= " AND (si1.record = 1)";
|
||||||
|
|
||||||
return Application_Common_Database::prepareAndExecute( $sql,
|
return Application_Common_Database::prepareAndExecute( $sql,
|
||||||
|
|
|
@ -22,6 +22,8 @@ class Application_Model_ShowInstance
|
||||||
return $this->_showInstance->getDbShowId();
|
return $this->_showInstance->getDbShowId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* TODO: A little inconsistent because other models have a getId() method
|
||||||
|
to get PK --RG */
|
||||||
public function getShowInstanceId()
|
public function getShowInstanceId()
|
||||||
{
|
{
|
||||||
return $this->_instanceId;
|
return $this->_instanceId;
|
||||||
|
@ -34,17 +36,17 @@ class Application_Model_ShowInstance
|
||||||
|
|
||||||
public function deleteRebroadcasts()
|
public function deleteRebroadcasts()
|
||||||
{
|
{
|
||||||
$con = Propel::getConnection();
|
|
||||||
|
|
||||||
$timestamp = gmdate("Y-m-d H:i:s");
|
$timestamp = gmdate("Y-m-d H:i:s");
|
||||||
$instance_id = $this->getShowInstanceId();
|
$instance_id = $this->getShowInstanceId();
|
||||||
|
$sql = <<<SQL
|
||||||
$sql = "DELETE FROM cc_show_instances"
|
DELETE FROM cc_show_instances
|
||||||
." WHERE starts > TIMESTAMP '$timestamp'"
|
WHERE starts > :timestamp::TIMESTAMP
|
||||||
." AND instance_id = $instance_id"
|
AND instance_id = :instanceId
|
||||||
." AND rebroadcast = 1";
|
AND rebroadcast = 1;
|
||||||
|
SQL;
|
||||||
$con->exec($sql);
|
Application_Common_Database::prepareAndExecute( $sql, array(
|
||||||
|
':instanceId' => $instance_id,
|
||||||
|
':timestamp' => $timestamp), 'execute');
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function is weird. It should return a boolean, but instead returns
|
/* This function is weird. It should return a boolean, but instead returns
|
||||||
|
@ -167,26 +169,33 @@ class Application_Model_ShowInstance
|
||||||
$con = Propel::getConnection();
|
$con = Propel::getConnection();
|
||||||
|
|
||||||
$instance_id = $this->getShowInstanceId();
|
$instance_id = $this->getShowInstanceId();
|
||||||
$sql = "SELECT starts from cc_schedule"
|
$sql = <<<SQL
|
||||||
." WHERE instance_id = $instance_id"
|
SELECT starts
|
||||||
." ORDER BY starts"
|
FROM cc_schedule
|
||||||
." LIMIT 1";
|
WHERE instance_id = :instanceId
|
||||||
|
ORDER BY starts LIMIT 1;
|
||||||
$scheduleStarts = $con->query($sql)->fetchColumn(0);
|
SQL;
|
||||||
|
$scheduleStarts = Application_Common_Database::prepareAndExecute( $sql,
|
||||||
|
array( ':instanceId' => $instance_id ), 'column' );
|
||||||
|
|
||||||
if ($scheduleStarts) {
|
if ($scheduleStarts) {
|
||||||
$scheduleStartsEpoch = strtotime($scheduleStarts);
|
$scheduleStartsEpoch = strtotime($scheduleStarts);
|
||||||
$showStartsEpoch = strtotime($this->getShowInstanceStart());
|
$showStartsEpoch = strtotime($this->getShowInstanceStart());
|
||||||
|
|
||||||
$diff = $showStartsEpoch - $scheduleStartsEpoch;
|
$diff = $showStartsEpoch - $scheduleStartsEpoch;
|
||||||
|
|
||||||
if ($diff != 0) {
|
if ($diff != 0) {
|
||||||
$sql = "UPDATE cc_schedule"
|
$sql = <<<SQL
|
||||||
." SET starts = starts + INTERVAL '$diff' second,"
|
UPDATE cc_schedule
|
||||||
." ends = ends + INTERVAL '$diff' second"
|
SET starts = starts + INTERVAL :diff1 SECOND,
|
||||||
." WHERE instance_id = $instance_id";
|
ends = ends + INTERVAL :diff2 SECOND
|
||||||
|
WHERE instance_id = :instanceId
|
||||||
$con->exec($sql);
|
SQL;
|
||||||
|
Application_Common_Database::prepareAndExecute($sql,
|
||||||
|
array(
|
||||||
|
':diff1' => $diff,
|
||||||
|
':diff2' => $diff,
|
||||||
|
':instanceId' => $instance_id ), 'execute');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Application_Model_RabbitMq::PushSchedule();
|
Application_Model_RabbitMq::PushSchedule();
|
||||||
|
@ -315,11 +324,6 @@ class Application_Model_ShowInstance
|
||||||
Application_Model_RabbitMq::PushSchedule();
|
Application_Model_RabbitMq::PushSchedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* FUNCTION SHOULD NOT BE CALLED
|
|
||||||
* - we are removing ability to resize just a single show instance
|
|
||||||
* -please use the resize method on the Show.php class.
|
|
||||||
*/
|
|
||||||
public function resizeShow($deltaDay, $deltaMin)
|
public function resizeShow($deltaDay, $deltaMin)
|
||||||
{
|
{
|
||||||
$con = Propel::getConnection();
|
$con = Propel::getConnection();
|
||||||
|
@ -356,6 +360,7 @@ class Application_Model_ShowInstance
|
||||||
$overlap = Application_Model_Show::getShows($utcStartDateTime, $utcEndDateTime);
|
$overlap = Application_Model_Show::getShows($utcStartDateTime, $utcEndDateTime);
|
||||||
|
|
||||||
if (count($overlap) > 0) {
|
if (count($overlap) > 0) {
|
||||||
|
// TODO : fix ghetto error handling -- RG
|
||||||
return "Should not overlap shows";
|
return "Should not overlap shows";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -363,9 +368,17 @@ class Application_Model_ShowInstance
|
||||||
|
|
||||||
//must update length of all rebroadcast instances.
|
//must update length of all rebroadcast instances.
|
||||||
if ($this->isRecorded()) {
|
if ($this->isRecorded()) {
|
||||||
$sql = "UPDATE cc_show_instances SET ends = (ends + interval '{$deltaDay} days' + interval '{$hours}:{$mins}')
|
$sql = <<<SQL
|
||||||
WHERE rebroadcast = 1 AND instance_id = {$this->_instanceId}";
|
UPDATE cc_show_instances
|
||||||
$con->exec($sql);
|
SET ends = (ends + interval :deltaDays + interval :interval)
|
||||||
|
WHERE rebroadcast = 1
|
||||||
|
AND instance_id = :instanceId;
|
||||||
|
SQL;
|
||||||
|
Application_Common_Database::prepareAndExecute( $sql, array(
|
||||||
|
':deltaDays' => "$deltaDay days",
|
||||||
|
':interval' => "$hours:$mins",
|
||||||
|
':instanceId' => $this->_instanceId ), 'execute');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setShowEnd($new_ends);
|
$this->setShowEnd($new_ends);
|
||||||
|
@ -745,102 +758,90 @@ SQL;
|
||||||
|
|
||||||
public static function GetLastShowInstance($p_timeNow)
|
public static function GetLastShowInstance($p_timeNow)
|
||||||
{
|
{
|
||||||
global $CC_CONFIG;
|
$sql = <<<SQL
|
||||||
$con = Propel::getConnection();
|
SELECT si.id
|
||||||
|
FROM cc_show_instances si
|
||||||
|
WHERE si.ends < :timeNow::TIMESTAMP
|
||||||
|
AND si.modified_instance = 'f'
|
||||||
|
ORDER BY si.ends DESC LIMIT 1;
|
||||||
|
SQL;
|
||||||
|
$id = Application_Common_Database( $sql, array(
|
||||||
|
':timeNow' => $p_timeNow ), 'column' );
|
||||||
|
|
||||||
$sql = "SELECT si.id"
|
return ($id ? new Application_Model_ShowInstance($id) : null );
|
||||||
." FROM $CC_CONFIG[showInstances] si"
|
|
||||||
." WHERE si.ends < TIMESTAMP '$p_timeNow'"
|
|
||||||
." AND si.modified_instance = 'f'"
|
|
||||||
." ORDER BY si.ends DESC"
|
|
||||||
." LIMIT 1";
|
|
||||||
|
|
||||||
$id = $con->query($sql)->fetchColumn(0);
|
|
||||||
if ($id) {
|
|
||||||
return new Application_Model_ShowInstance($id);
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function GetCurrentShowInstance($p_timeNow)
|
public static function GetCurrentShowInstance($p_timeNow)
|
||||||
{
|
{
|
||||||
global $CC_CONFIG;
|
|
||||||
$con = Propel::getConnection();
|
|
||||||
|
|
||||||
/* Orderby si.starts descending, because in some cases
|
/* Orderby si.starts descending, because in some cases
|
||||||
* we can have multiple shows overlapping each other. In
|
* we can have multiple shows overlapping each other. In
|
||||||
* this case, the show that started later is the one that
|
* this case, the show that started later is the one that
|
||||||
* is actually playing, and so this is the one we want.
|
* is actually playing, and so this is the one we want.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sql = "SELECT si.id"
|
$sql = <<<SQL
|
||||||
." FROM $CC_CONFIG[showInstances] si"
|
SELECT si.id
|
||||||
." WHERE si.starts <= TIMESTAMP '$p_timeNow'"
|
FROM cc_show_instances si
|
||||||
." AND si.ends > TIMESTAMP '$p_timeNow'"
|
WHERE si.starts <= :timeNow1::TIMESTAMP
|
||||||
." AND si.modified_instance = 'f'"
|
AND si.ends > :timeNow2::TIMESTAMP
|
||||||
." ORDER BY si.starts DESC"
|
AND si.modified_instance = 'f'
|
||||||
." LIMIT 1";
|
ORDER BY si.starts DESC LIMIT 1
|
||||||
|
SQL;
|
||||||
|
|
||||||
$id = $con->query($sql)->fetchColumn(0);
|
$id = Application_Common_Database( $sql, array(
|
||||||
if ($id) {
|
':timeNow1' => $p_timeNow,
|
||||||
return new Application_Model_ShowInstance($id);
|
':timeNow2' => $p_timeNow ), 'column');
|
||||||
} else {
|
|
||||||
return null;
|
return ( $id ? new Application_Model_ShowInstance($id) : null );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function GetNextShowInstance($p_timeNow)
|
public static function GetNextShowInstance($p_timeNow)
|
||||||
{
|
{
|
||||||
global $CC_CONFIG;
|
$sql = <<<SQL
|
||||||
$con = Propel::getConnection();
|
SELECT si.id
|
||||||
|
FROM cc_show_instances si
|
||||||
$sql = "SELECT si.id"
|
WHERE si.starts > :timeNow::TIMESTAMP
|
||||||
." FROM $CC_CONFIG[showInstances] si"
|
AND si.modified_instance = 'f'
|
||||||
." WHERE si.starts > TIMESTAMP '$p_timeNow'"
|
ORDER BY si.starts
|
||||||
." AND si.modified_instance = 'f'"
|
LIMIT 1
|
||||||
." ORDER BY si.starts"
|
SQL;
|
||||||
." LIMIT 1";
|
$id = Application_Common_Database::prepareAndExecute( $sql,
|
||||||
|
array( 'timeNow' => $p_timeNow ), 'column' );
|
||||||
$id = $con->query($sql)->fetchColumn(0);
|
return ( $id ? new Application_Model_ShowInstance($id) : null );
|
||||||
if ($id) {
|
|
||||||
return new Application_Model_ShowInstance($id);
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns number of show instances that ends later than $day
|
// returns number of show instances that ends later than $day
|
||||||
public static function GetShowInstanceCount($day)
|
public static function GetShowInstanceCount($day)
|
||||||
{
|
{
|
||||||
global $CC_CONFIG;
|
$sql = <<<SQL
|
||||||
$con = Propel::getConnection();
|
SELECT count(*) AS cnt
|
||||||
$sql = "SELECT count(*) as cnt FROM $CC_CONFIG[showInstances] WHERE ends < '$day'";
|
FROM cc_show_instances
|
||||||
|
WHERE ends < '$day'
|
||||||
return $con->query($sql)->fetchColumn(0);
|
SQL;
|
||||||
|
return Application_Common_Database::prepareAndExecute( $sql,
|
||||||
|
array( ':day' => $day ), 'column' );
|
||||||
}
|
}
|
||||||
|
|
||||||
// this returns end timestamp of all shows that are in the range and has live DJ set up
|
// this returns end timestamp of all shows that are in the range and has live DJ set up
|
||||||
public static function GetEndTimeOfNextShowWithLiveDJ($p_startTime, $p_endTime)
|
public static function GetEndTimeOfNextShowWithLiveDJ($p_startTime, $p_endTime)
|
||||||
{
|
{
|
||||||
global $CC_CONFIG;
|
$sql = <<<SQL
|
||||||
$con = Propel::getConnection();
|
SELECT ends
|
||||||
|
FROM cc_show_instances AS si
|
||||||
$sql = "SELECT ends
|
JOIN cc_show AS sh ON si.show_id = sh.id
|
||||||
FROM cc_show_instances as si
|
WHERE si.ends > :startTime::TIMESTAMP
|
||||||
JOIN cc_show as sh ON si.show_id = sh.id
|
AND si.ends < :endTime::TIMESTAMP
|
||||||
WHERE si.ends > '$p_startTime' and si.ends < '$p_endTime' and (sh.live_stream_using_airtime_auth or live_stream_using_custom_auth)
|
AND (sh.live_stream_using_airtime_auth
|
||||||
ORDER BY si.ends";
|
OR live_stream_using_custom_auth)
|
||||||
|
ORDER BY si.ends
|
||||||
return $con->query($sql)->fetchAll();
|
SQL;
|
||||||
|
return Application_Common_Database::prepareAndExecute( $sql, array(
|
||||||
|
':startTime' => $p_startTime,
|
||||||
|
':endTime' => $p_endTime), 'all');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isRepeating()
|
public function isRepeating()
|
||||||
{
|
{
|
||||||
if ($this->getShow()->isRepeating()) {
|
return $this->getShow()->isRepeating();
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -413,8 +413,10 @@ class Application_Model_StoredFile
|
||||||
return "ogg";
|
return "ogg";
|
||||||
} elseif ($mime == "audio/mp3" || $mime == "audio/mpeg") {
|
} elseif ($mime == "audio/mp3" || $mime == "audio/mpeg") {
|
||||||
return "mp3";
|
return "mp3";
|
||||||
} elseif ($mime == "audio/x/flac") {
|
} elseif ($mime == "audio/x-flac") {
|
||||||
return "flac";
|
return "flac";
|
||||||
|
} else {
|
||||||
|
throw new Exception("Unknown $mime");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
debian/control
vendored
1
debian/control
vendored
|
@ -37,6 +37,7 @@ Depends: apache2,
|
||||||
php-pear,
|
php-pear,
|
||||||
php5-pgsql,
|
php5-pgsql,
|
||||||
python,
|
python,
|
||||||
|
pwgen,
|
||||||
rabbitmq-server,
|
rabbitmq-server,
|
||||||
sudo,
|
sudo,
|
||||||
sysv-rc,
|
sysv-rc,
|
||||||
|
|
|
@ -244,7 +244,7 @@ def normalized_metadata(md, original_path):
|
||||||
format_rules = {
|
format_rules = {
|
||||||
'MDATA_KEY_TRACKNUMBER' : parse_int,
|
'MDATA_KEY_TRACKNUMBER' : parse_int,
|
||||||
'MDATA_KEY_FILEPATH' : lambda x: os.path.normpath(x),
|
'MDATA_KEY_FILEPATH' : lambda x: os.path.normpath(x),
|
||||||
'MDATA_KEY_MIME' : lambda x: x.replace('-','/'),
|
#'MDATA_KEY_MIME' : lambda x: x.replace('-','/'),
|
||||||
'MDATA_KEY_BPM' : lambda x: x[0:8],
|
'MDATA_KEY_BPM' : lambda x: x[0:8],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,14 @@ get_include_path(),
|
||||||
realpath($CC_CONFIG['phpDir'] . '/library')
|
realpath($CC_CONFIG['phpDir'] . '/library')
|
||||||
)));
|
)));
|
||||||
|
|
||||||
|
function __autoload($classname){
|
||||||
|
global $CC_CONFIG;
|
||||||
|
$info = explode('_', $classname);
|
||||||
|
if (isset($info[2])) {
|
||||||
|
$filename = $info[2].".php";
|
||||||
|
require_once($CC_CONFIG['phpDir'].'/application/models/'.$filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
require_once($CC_CONFIG['phpDir'].'/application/models/User.php');
|
require_once($CC_CONFIG['phpDir'].'/application/models/User.php');
|
||||||
require_once($CC_CONFIG['phpDir'].'/application/models/StoredFile.php');
|
require_once($CC_CONFIG['phpDir'].'/application/models/StoredFile.php');
|
||||||
require_once($CC_CONFIG['phpDir'].'/application/models/Playlist.php');
|
require_once($CC_CONFIG['phpDir'].'/application/models/Playlist.php');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue