Merge branch 'devel' of dev.sourcefabric.org:airtime into devel

This commit is contained in:
Rudi Grinberg 2012-09-06 17:23:58 -04:00
commit 33326ec052
7 changed files with 125 additions and 102 deletions

View File

@ -1,7 +1,7 @@
<?php <?php
class Application_Common_Database class Application_Common_Database
{ {
public static function prepareAndExecute($sql, array $paramValueMap, public static function prepareAndExecute($sql, array $paramValueMap,
$type='all', $fetchType=PDO::FETCH_ASSOC) $type='all', $fetchType=PDO::FETCH_ASSOC)
{ {
$con = Propel::getConnection(); $con = Propel::getConnection();
@ -15,8 +15,13 @@ class Application_Common_Database
$rows = $stmt->fetch($fetchType); $rows = $stmt->fetch($fetchType);
} else if ($type == 'column'){ } else if ($type == 'column'){
$rows = $stmt->fetchColumn(); $rows = $stmt->fetchColumn();
} else { } else if ($type == 'all') {
$rows = $stmt->fetchAll($fetchType); $rows = $stmt->fetchAll($fetchType);
} else if ($type == 'execute') {
$rows = null;
} else {
$msg = "bad type passed: type($type)";
throw new Exception("Error: $msg");
} }
} else { } else {
$msg = implode(',', $stmt->errorInfo()); $msg = implode(',', $stmt->errorInfo());

View File

@ -175,7 +175,7 @@ class Application_Model_Playlist implements Application_Model_LibraryEditable
f.length AS orig_length f.length AS orig_length
FROM cc_playlistcontents AS pc FROM cc_playlistcontents AS pc
JOIN cc_files AS f ON pc.file_id=f.id JOIN cc_files AS f ON pc.file_id=f.id
WHERE pc.playlist_id = {$this->id} WHERE pc.playlist_id = :playlist_id1
AND TYPE = 0) AND TYPE = 0)
UNION ALL UNION ALL
(SELECT pc.id AS id, (SELECT pc.id AS id,
@ -194,7 +194,7 @@ class Application_Model_Playlist implements Application_Model_LibraryEditable
FROM cc_playlistcontents AS pc FROM cc_playlistcontents AS pc
JOIN cc_webstream AS ws ON pc.stream_id=ws.id JOIN cc_webstream AS ws ON pc.stream_id=ws.id
LEFT JOIN cc_subjs AS sub ON sub.id = ws.creator_id LEFT JOIN cc_subjs AS sub ON sub.id = ws.creator_id
WHERE pc.playlist_id = {$this->id} WHERE pc.playlist_id = :playlist_id2
AND pc.TYPE = 1) AND pc.TYPE = 1)
UNION ALL UNION ALL
(SELECT pc.id AS id, (SELECT pc.id AS id,
@ -213,13 +213,12 @@ class Application_Model_Playlist implements Application_Model_LibraryEditable
FROM cc_playlistcontents AS pc FROM cc_playlistcontents AS pc
JOIN cc_block AS bl ON pc.block_id=bl.id JOIN cc_block AS bl ON pc.block_id=bl.id
JOIN cc_subjs AS sbj ON bl.creator_id=sbj.id JOIN cc_subjs AS sbj ON bl.creator_id=sbj.id
WHERE pc.playlist_id = {$this->id} WHERE pc.playlist_id = :playlist_id3
AND pc.TYPE = 2)) AS temp AND pc.TYPE = 2)) AS temp
ORDER BY temp.position; ORDER BY temp.position;
SQL; SQL;
$con = Propel::getConnection(); $rows = Application_Common_Database::prepareAndExecute($sql, array(':playlist_id1'=>$this->id, ':playlist_id2'=>$this->id, ':playlist_id3'=>$this->id));
$rows = $con->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$offset = 0; $offset = 0;
foreach ($rows as &$row) { foreach ($rows as &$row) {
@ -291,9 +290,9 @@ SQL;
{ {
$sql = "SELECT bl.id FROM cc_playlistcontents as pc $sql = "SELECT bl.id FROM cc_playlistcontents as pc
JOIN cc_block as bl ON pc.type=2 AND pc.block_id=bl.id AND bl.type='dynamic' JOIN cc_block as bl ON pc.type=2 AND pc.block_id=bl.id AND bl.type='dynamic'
WHERE playlist_id={$this->id} AND pc.type=2"; WHERE playlist_id=:playlist_id AND pc.type=2";
$r = $this->con->query($sql);
$result = $r->fetchAll(PDO::FETCH_ASSOC); $result = Application_Common_Database::prepareAndExecute($sql, array(':playlist_id'=>$this->id));
return $result; return $result;
} }
@ -625,9 +624,8 @@ SQL;
if (!is_null($fadeIn)) { if (!is_null($fadeIn)) {
$sql = "SELECT INTERVAL '{$fadeIn}' > INTERVAL '{$clipLength}'"; $sql = "SELECT INTERVAL :fadein > INTERVAL '{$clipLength}'";
$r = $this->con->query($sql); if (Application_Common_Database::prepareAndExecute($sql, array(':fadein'=>$fadeIn), 'column')) {
if ($r->fetchColumn(0)) {
//"Fade In can't be larger than overall playlength."; //"Fade In can't be larger than overall playlength.";
$fadeIn = $clipLength; $fadeIn = $clipLength;
} }
@ -635,9 +633,8 @@ SQL;
} }
if (!is_null($fadeOut)) { if (!is_null($fadeOut)) {
$sql = "SELECT INTERVAL '{$fadeOut}' > INTERVAL '{$clipLength}'"; $sql = "SELECT INTERVAL :fadeout > INTERVAL '{$clipLength}'";
$r = $this->con->query($sql); if (Application_Common_Database::prepareAndExecute($sql, array(':fadeout'=>$fadeOut), 'column')) {
if ($r->fetchColumn(0)) {
//Fade Out can't be larger than overall playlength."; //Fade Out can't be larger than overall playlength.";
$fadeOut = $clipLength; $fadeOut = $clipLength;
} }
@ -727,25 +724,22 @@ SQL;
$cueOut = $origLength; $cueOut = $origLength;
} }
$sql = "SELECT INTERVAL '{$cueIn}' > INTERVAL '{$cueOut}'"; $sql = "SELECT INTERVAL :cueIn > INTERVAL :cueOut";
$r = $this->con->query($sql); if (Application_Common_Database::prepareAndExecute($sql, array(':cueIn'=>$cueIn, ':cueOut'=>$cueOut), 'column')) {
if ($r->fetchColumn(0)) {
$errArray["error"] = "Can't set cue in to be larger than cue out."; $errArray["error"] = "Can't set cue in to be larger than cue out.";
return $errArray; return $errArray;
} }
$sql = "SELECT INTERVAL '{$cueOut}' > INTERVAL '{$origLength}'"; $sql = "SELECT INTERVAL :cueOut > INTERVAL :origLength";
$r = $this->con->query($sql); if (Application_Common_Database::prepareAndExecute($sql, array(':cueOut'=>$cueOut, ':origLength'=>$origLength), 'column')) {
if ($r->fetchColumn(0)) {
$errArray["error"] = "Can't set cue out to be greater than file length."; $errArray["error"] = "Can't set cue out to be greater than file length.";
return $errArray; return $errArray;
} }
$sql = "SELECT INTERVAL '{$cueOut}' - INTERVAL '{$cueIn}'"; $sql = "SELECT INTERVAL :cueOut - INTERVAL :cueIn";
$r = $this->con->query($sql); $cliplength = Application_Common_Database::prepareAndExecute($sql, array(':cueOut'=>$cueOut, ':cueIn'=>$cueIn), 'column');
$cliplength = $r->fetchColumn(0);
$row->setDbCuein($cueIn); $row->setDbCuein($cueIn);
$row->setDbCueout($cueOut); $row->setDbCueout($cueOut);
@ -753,17 +747,15 @@ SQL;
} elseif (!is_null($cueIn)) { } elseif (!is_null($cueIn)) {
$sql = "SELECT INTERVAL '{$cueIn}' > INTERVAL '{$oldCueOut}'"; $sql = "SELECT INTERVAL :cueIn > INTERVAL :oldCueOut";
$r = $this->con->query($sql); if (Application_Common_Database::prepareAndExecute($sql, array(':cueIn'=>$cueIn, ':oldCueOut'=>$oldCueOut), 'column')) {
if ($r->fetchColumn(0)) {
$errArray["error"] = "Can't set cue in to be larger than cue out."; $errArray["error"] = "Can't set cue in to be larger than cue out.";
return $errArray; return $errArray;
} }
$sql = "SELECT INTERVAL '{$oldCueOut}' - INTERVAL '{$cueIn}'"; $sql = "SELECT INTERVAL :oldCueOut - INTERVAL :cueIn";
$r = $this->con->query($sql); $cliplength = Application_Common_Database::prepareAndExecute($sql, array(':cueIn'=>$cueIn, ':oldCueOut'=>$oldCueOut, 'column'));
$cliplength = $r->fetchColumn(0);
$row->setDbCuein($cueIn); $row->setDbCuein($cueIn);
$row->setDBCliplength($cliplength); $row->setDBCliplength($cliplength);
@ -773,25 +765,22 @@ SQL;
$cueOut = $origLength; $cueOut = $origLength;
} }
$sql = "SELECT INTERVAL '{$cueOut}' < INTERVAL '{$oldCueIn}'"; $sql = "SELECT INTERVAL :cueOut < INTERVAL :oldCueIn";
$r = $this->con->query($sql); if (Application_Common_Database::prepareAndExecute($sql, array(':cueOut'=>$cueOut, ':oldCueIn'=>$oldCueIn, 'column'))) {
if ($r->fetchColumn(0)) {
$errArray["error"] = "Can't set cue out to be smaller than cue in."; $errArray["error"] = "Can't set cue out to be smaller than cue in.";
return $errArray; return $errArray;
} }
$sql = "SELECT INTERVAL '{$cueOut}' > INTERVAL '{$origLength}'"; $sql = "SELECT INTERVAL :cueOut > INTERVAL :origLength";
$r = $this->con->query($sql); if (Application_Common_Database::prepareAndExecute($sql, array(':cueOut'=>$cueOut, ':origLength'=>$origLength, 'column'))) {
if ($r->fetchColumn(0)) {
$errArray["error"] = "Can't set cue out to be greater than file length."; $errArray["error"] = "Can't set cue out to be greater than file length.";
return $errArray; return $errArray;
} }
$sql = "SELECT INTERVAL '{$cueOut}' - INTERVAL '{$oldCueIn}'"; $sql = "SELECT INTERVAL :cueOut - INTERVAL :oldCueIn";
$r = $this->con->query($sql); $cliplength = Application_Common_Database::prepareAndExecute($sql, array(':cueOut'=>$cueOut, ':oldCueIn'=>$oldCueIn, 'column'));
$cliplength = $r->fetchColumn(0);
$row->setDbCueout($cueOut); $row->setDbCueout($cueOut);
$row->setDBCliplength($cliplength); $row->setDBCliplength($cliplength);
@ -799,16 +788,14 @@ SQL;
$cliplength = $row->getDbCliplength(); $cliplength = $row->getDbCliplength();
$sql = "SELECT INTERVAL '{$fadeIn}' > INTERVAL '{$cliplength}'"; $sql = "SELECT INTERVAL :fadeIn > INTERVAL :cliplength";
$r = $this->con->query($sql); if (Application_Common_Database::prepareAndExecute($sql, array(':fadeIn'=>$fadeIn, ':cliplength'=>$cliplength, 'column'))) {
if ($r->fetchColumn(0)) {
$fadeIn = $cliplength; $fadeIn = $cliplength;
$row->setDbFadein($fadeIn); $row->setDbFadein($fadeIn);
} }
$sql = "SELECT INTERVAL '{$fadeOut}' > INTERVAL '{$cliplength}'"; $sql = "SELECT INTERVAL :fadeOut > INTERVAL :cliplength";
$r = $this->con->query($sql); if (Application_Common_Database::prepareAndExecute($sql, array(':fadeOut'=>$fadeOut, ':cliplength'=>$cliplength, 'column'))) {
if ($r->fetchColumn(0)) {
$fadeOut = $cliplength; $fadeOut = $cliplength;
$row->setDbFadein($fadeOut); $row->setDbFadein($fadeOut);
} }

View File

@ -18,48 +18,57 @@ class Application_Model_Preference
//Check if key already exists //Check if key already exists
$sql = "SELECT COUNT(*) FROM cc_pref" $sql = "SELECT COUNT(*) FROM cc_pref"
." WHERE keystr = '$key'"; ." WHERE keystr = :key";
$paramMap = array();
$paramMap[':key'] = $key;
//For user specific preference, check if id matches as well //For user specific preference, check if id matches as well
if ($isUserValue) { if ($isUserValue) {
$sql .= " AND subjid = '$id'"; $sql .= " AND subjid = :id";
$paramMap[':id'] = $id;
} }
$result = $con->query($sql)->fetchColumn(0); $result = Application_Common_Database::prepareAndExecute($sql, $paramMap, 'column');
if ($value == "") { if ($value == "") {
$value = "NULL"; $value = "NULL";
} else { } else {
$value = "'$value'"; $value = "$value";
} }
$paramMap = array();
if ($result == 1) { if ($result == 1) {
// result found // result found
if (is_null($id) || !$isUserValue) { if (is_null($id) || !$isUserValue) {
// system pref // system pref
$sql = "UPDATE cc_pref" $sql = "UPDATE cc_pref"
." SET subjid = NULL, valstr = $value" ." SET subjid = NULL, valstr = :value"
." WHERE keystr = '$key'"; ." WHERE keystr = :key";
} else { } else {
// user pref // user pref
$sql = "UPDATE cc_pref" $sql = "UPDATE cc_pref"
. " SET valstr = $value" . " SET valstr = :value"
. " WHERE keystr = '$key' AND subjid = $id"; . " WHERE keystr = :key AND subjid = :id";
$paramMap[':id'] = $id;
} }
} else { } else {
// result not found // result not found
if (is_null($id) || !$isUserValue) { if (is_null($id) || !$isUserValue) {
// system pref // system pref
$sql = "INSERT INTO cc_pref (keystr, valstr)" $sql = "INSERT INTO cc_pref (keystr, valstr)"
." VALUES ('$key', $value)"; ." VALUES (:key, :value)";
} else { } else {
// user pref // user pref
$sql = "INSERT INTO cc_pref (subjid, keystr, valstr)" $sql = "INSERT INTO cc_pref (subjid, keystr, valstr)"
." VALUES ($id, '$key', $value)"; ." VALUES (:id, :key, :value)";
$paramMap[':id'] = $id;
} }
} }
$paramMap[':key'] = $key;
$paramMap[':value'] = $value;
$con->exec($sql); Application_Common_Database::prepareAndExecute($sql, $paramMap, 'execute');
} catch (Exception $e) { } catch (Exception $e) {
header('HTTP/1.0 503 Service Unavailable'); header('HTTP/1.0 503 Service Unavailable');
@ -77,28 +86,39 @@ class Application_Model_Preference
//Check if key already exists //Check if key already exists
$sql = "SELECT COUNT(*) FROM cc_pref" $sql = "SELECT COUNT(*) FROM cc_pref"
." WHERE keystr = '$key'"; ." WHERE keystr = '$key'";
/*." WHERE keystr = :key";
$paramMap = array();
$paramMap[':key'] = $key;*/
//For user specific preference, check if id matches as well //For user specific preference, check if id matches as well
if ($isUserValue) { if ($isUserValue) {
$auth = Zend_Auth::getInstance(); $auth = Zend_Auth::getInstance();
if ($auth->hasIdentity()) { if ($auth->hasIdentity()) {
$id = $auth->getIdentity()->id; $id = $auth->getIdentity()->id;
$sql .= " AND subjid = '$id'"; $sql .= " AND subjid = '$id'";
/*$sql .= " AND subjid = :id";
$paramMap[':id'] = $id;*/
} }
} }
$result = $con->query($sql)->fetchColumn(0); $result = $con->query($sql)->fetchColumn(0);
//$result = Application_Common_Database::prepareAndExecute($sql, $paramMap, 'column');
if ($result == 0) if ($result == 0)
return ""; return "";
else { else {
$sql = "SELECT valstr FROM cc_pref" $sql = "SELECT valstr FROM cc_pref"
." WHERE keystr = '$key'"; ." WHERE keystr = '$key'";
/*." WHERE keystr = :key";
$paramMap = array();
$paramMap[':key'] = $key;*/
//For user specific preference, check if id matches as well //For user specific preference, check if id matches as well
if ($isUserValue && $auth->hasIdentity()) { if ($isUserValue && $auth->hasIdentity()) {
$sql .= " AND subjid = '$id'"; $sql .= " AND subjid = '$id'";
/*$sql .= " AND subjid = :id";
$paramMap[':id'] = $id;*/
} }
$result = $con->query($sql)->fetchColumn(0); $result = $con->query($sql)->fetchColumn(0);
//$result = Application_Common_Database::prepareAndExecute($sql, $paramMap, 'column');
return ($result !== false) ? $result : ""; return ($result !== false) ? $result : "";
} }

View File

@ -10,10 +10,9 @@ class Application_Model_Schedule
public function IsFileScheduledInTheFuture($p_fileId) public function IsFileScheduledInTheFuture($p_fileId)
{ {
global $CC_CONFIG; global $CC_CONFIG;
$con = Propel::getConnection();
$sql = "SELECT COUNT(*) FROM ".$CC_CONFIG["scheduleTable"] $sql = "SELECT COUNT(*) FROM ".$CC_CONFIG["scheduleTable"]
." WHERE file_id = {$p_fileId} AND ends > NOW() AT TIME ZONE 'UTC'"; ." WHERE file_id = :file_id AND ends > NOW() AT TIME ZONE 'UTC'";
$count = $con->query($sql)->fetchColumn(0); $count = Application_Common_Database::prepareAndExecute($sql, array(':file_id'=>$p_fileId), 'column');
return (is_numeric($count) && ($count != '0')); return (is_numeric($count) && ($count != '0'));
} }
@ -52,7 +51,8 @@ class Application_Model_Schedule
"currentShow"=>$shows['currentShow'], "currentShow"=>$shows['currentShow'],
"nextShow"=>$shows['nextShow'], "nextShow"=>$shows['nextShow'],
"timezone"=> date("T"), "timezone"=> date("T"),
"timezoneOffset"=> date("Z")); "timezoneOffset"=> date("Z")
);
return $range; return $range;
} }
@ -71,7 +71,6 @@ class Application_Model_Schedule
return; return;
} }
global $CC_CONFIG;
$con = Propel::getConnection(); $con = Propel::getConnection();
$sql = "SELECT %%columns%% st.starts as starts, st.ends as ends, $sql = "SELECT %%columns%% st.starts as starts, st.ends as ends,
st.media_item_played as media_item_played, si.ends as show_ends st.media_item_played as media_item_played, si.ends as show_ends
@ -88,14 +87,18 @@ class Application_Model_Schedule
LEFT JOIN (SELECT * FROM cc_webstream_metadata ORDER BY start_time DESC LIMIT 1) AS wm on st.id = wm.instance_id"; LEFT JOIN (SELECT * FROM cc_webstream_metadata ORDER BY start_time DESC LIMIT 1) AS wm on st.id = wm.instance_id";
$predicateArr = array(); $predicateArr = array();
$paramMap = array();
if (isset($p_previousShowID)) { if (isset($p_previousShowID)) {
$predicateArr[] = 'st.instance_id = '.$p_previousShowID; $predicateArr[] = 'st.instance_id = :previousShowId';
$paramMap[':previousShowId'] = $p_previousShowID;
} }
if (isset($p_currentShowID)) { if (isset($p_currentShowID)) {
$predicateArr[] = 'st.instance_id = '.$p_currentShowID; $predicateArr[] = 'st.instance_id = :currentShowId';
$paramMap[':currentShowId'] = $p_currentShowID;
} }
if (isset($p_nextShowID)) { if (isset($p_nextShowID)) {
$predicateArr[] = 'st.instance_id = '.$p_nextShowID; $predicateArr[] = 'st.instance_id = :nextShowId';
$paramMap[':nextShowId'] = $p_nextShowID;
} }
$sql .= " (".implode(" OR ", $predicateArr).") "; $sql .= " (".implode(" OR ", $predicateArr).") ";
@ -109,7 +112,7 @@ class Application_Model_Schedule
$sql = "SELECT * FROM (($filesSql) UNION ($streamSql)) AS unioned ORDER BY starts"; $sql = "SELECT * FROM (($filesSql) UNION ($streamSql)) AS unioned ORDER BY starts";
$rows = $con->query($sql)->fetchAll(PDO::FETCH_ASSOC); $rows = Application_Common_Database::prepareAndExecute($sql, $paramMap);
$numberOfRows = count($rows); $numberOfRows = count($rows);
$results['previous'] = null; $results['previous'] = null;
@ -169,7 +172,6 @@ class Application_Model_Schedule
public static function GetLastScheduleItem($p_timeNow) public static function GetLastScheduleItem($p_timeNow)
{ {
global $CC_CONFIG; global $CC_CONFIG;
$con = Propel::getConnection();
$sql = "SELECT" $sql = "SELECT"
." ft.artist_name, ft.track_title," ." ft.artist_name, ft.track_title,"
." st.starts as starts, st.ends as ends" ." st.starts as starts, st.ends as ends"
@ -178,13 +180,13 @@ class Application_Model_Schedule
." ON st.file_id = ft.id" ." ON st.file_id = ft.id"
." LEFT JOIN $CC_CONFIG[showInstances] sit" ." LEFT JOIN $CC_CONFIG[showInstances] sit"
." ON st.instance_id = sit.id" ." ON st.instance_id = sit.id"
." WHERE st.ends < TIMESTAMP '$p_timeNow'" ." WHERE st.ends < TIMESTAMP :timeNow"
." AND st.starts >= sit.starts" //this and the next line are necessary since we can overbook shows. ." AND st.starts >= sit.starts" //this and the next line are necessary since we can overbook shows.
." AND st.starts < sit.ends" ." AND st.starts < sit.ends"
." ORDER BY st.ends DESC" ." ORDER BY st.ends DESC"
." LIMIT 1"; ." LIMIT 1";
$row = $con->query($sql)->fetchAll(); $row = Application_Common_Database::prepareAndExecute($sql, array(':timeNow'=>$p_timeNow));
return $row; return $row;
} }
@ -192,7 +194,6 @@ class Application_Model_Schedule
public static function GetCurrentScheduleItem($p_timeNow, $p_instanceId) public static function GetCurrentScheduleItem($p_timeNow, $p_instanceId)
{ {
global $CC_CONFIG; global $CC_CONFIG;
$con = Propel::getConnection();
/* Note that usually there will be one result returned. In some /* Note that usually there will be one result returned. In some
* rare cases two songs are returned. This happens when a track * rare cases two songs are returned. This happens when a track
* that was overbooked from a previous show appears as if it * that was overbooked from a previous show appears as if it
@ -204,13 +205,13 @@ class Application_Model_Schedule
." FROM $CC_CONFIG[scheduleTable] st" ." FROM $CC_CONFIG[scheduleTable] st"
." LEFT JOIN $CC_CONFIG[filesTable] ft" ." LEFT JOIN $CC_CONFIG[filesTable] ft"
." ON st.file_id = ft.id" ." ON st.file_id = ft.id"
." WHERE st.starts <= TIMESTAMP '$p_timeNow'" ." WHERE st.starts <= TIMESTAMP :timeNow1"
." AND st.instance_id = $p_instanceId" ." AND st.instance_id = :instanceId"
." AND st.ends > TIMESTAMP '$p_timeNow'" ." AND st.ends > TIMESTAMP :timeNow2"
." ORDER BY st.starts DESC" ." ORDER BY st.starts DESC"
." LIMIT 1"; ." LIMIT 1";
$row = $con->query($sql)->fetchAll(); $row = Application_Common_Database::prepareAndExecute($sql, array(':timeNow1'=>$p_timeNow, ':instanceId'=>$p_instanceId, ':timeNow2'=>$p_timeNow,));
return $row; return $row;
} }
@ -218,7 +219,6 @@ class Application_Model_Schedule
public static function GetNextScheduleItem($p_timeNow) public static function GetNextScheduleItem($p_timeNow)
{ {
global $CC_CONFIG; global $CC_CONFIG;
$con = Propel::getConnection();
$sql = "SELECT" $sql = "SELECT"
." ft.artist_name, ft.track_title," ." ft.artist_name, ft.track_title,"
." st.starts as starts, st.ends as ends" ." st.starts as starts, st.ends as ends"
@ -227,13 +227,13 @@ class Application_Model_Schedule
." ON st.file_id = ft.id" ." ON st.file_id = ft.id"
." LEFT JOIN $CC_CONFIG[showInstances] sit" ." LEFT JOIN $CC_CONFIG[showInstances] sit"
." ON st.instance_id = sit.id" ." ON st.instance_id = sit.id"
." WHERE st.starts > TIMESTAMP '$p_timeNow'" ." WHERE st.starts > TIMESTAMP :timeNow"
." AND st.starts >= sit.starts" //this and the next line are necessary since we can overbook shows. ." AND st.starts >= sit.starts" //this and the next line are necessary since we can overbook shows.
." AND st.starts < sit.ends" ." AND st.starts < sit.ends"
." ORDER BY st.starts" ." ORDER BY st.starts"
." LIMIT 1"; ." LIMIT 1";
$row = $con->query($sql)->fetchAll(); $row = Application_Common_Database::prepareAndExecute($sql, array(':timeNow'=>$p_timeNow));
return $row; return $row;
} }
@ -514,7 +514,6 @@ SQL;
public static function GetItems($p_startTime, $p_endTime) public static function GetItems($p_startTime, $p_endTime)
{ {
global $CC_CONFIG; global $CC_CONFIG;
$con = Propel::getConnection();
$baseQuery = "SELECT st.file_id AS file_id," $baseQuery = "SELECT st.file_id AS file_id,"
." st.id AS id," ." st.id AS id,"
@ -540,15 +539,15 @@ SQL;
." LEFT JOIN cc_webstream AS ws" ." LEFT JOIN cc_webstream AS ws"
." ON st.stream_id = ws.id"; ." ON st.stream_id = ws.id";
$predicates = " WHERE st.ends > '$p_startTime'" $predicates = " WHERE st.ends > :startTime1"
." AND st.starts < '$p_endTime'" ." AND st.starts < :endTime"
." AND st.playout_status > 0" ." AND st.playout_status > 0"
." AND si.ends > '$p_startTime'" ." AND si.ends > :startTime2"
." ORDER BY st.starts"; ." ORDER BY st.starts";
$sql = $baseQuery.$predicates; $sql = $baseQuery.$predicates;
$rows = $con->query($sql)->fetchAll(); $rows = Application_Common_Database::prepareAndExecute($sql, array(':startTime1'=>$p_startTime, ':endTime'=>$p_endTime, ':startTime2'=>$p_startTime));
if (count($rows) < 3) { if (count($rows) < 3) {
Logging::debug("Get Schedule: Less than 3 results returned. Doing another query since we need a minimum of 3 results."); Logging::debug("Get Schedule: Less than 3 results returned. Doing another query since we need a minimum of 3 results.");
@ -557,15 +556,15 @@ SQL;
$dt->add(new DateInterval("PT24H")); $dt->add(new DateInterval("PT24H"));
$range_end = $dt->format("Y-m-d H:i:s"); $range_end = $dt->format("Y-m-d H:i:s");
$predicates = " WHERE st.ends > '$p_startTime'" $predicates = " WHERE st.ends > :startTime1"
." AND st.starts < '$range_end'" ." AND st.starts < :rangeEnd"
." AND st.playout_status > 0" ." AND st.playout_status > 0"
." AND si.ends > '$p_startTime'" ." AND si.ends > :startTime2"
." ORDER BY st.starts" ." ORDER BY st.starts"
." LIMIT 3"; ." LIMIT 3";
$sql = $baseQuery.$predicates; $sql = $baseQuery.$predicates;
$rows = $con->query($sql)->fetchAll(); $rows = Application_Common_Database::prepareAndExecute($sql, array(':startTime1'=>$p_startTime, ':rangeEnd'=>$range_end, ':startTime2'=>$p_startTime));
} }
return $rows; return $rows;
@ -748,9 +747,8 @@ SQL;
public static function deleteWithFileId($fileId) public static function deleteWithFileId($fileId)
{ {
global $CC_CONFIG; global $CC_CONFIG;
$con = Propel::getConnection(); $sql = "DELETE FROM ".$CC_CONFIG["scheduleTable"]." WHERE file_id=:file_id";
$sql = "DELETE FROM ".$CC_CONFIG["scheduleTable"]." WHERE file_id=$fileId"; $res = Application_Common_Database::prepareAndExecute($sql, array(':file_id'=>$fileId), 'execute');
$res = $con->query($sql);
} }
public static function createNewFormSections($p_view) public static function createNewFormSections($p_view)
@ -1091,7 +1089,7 @@ SQL;
and date(starts) >= (date('{$show_end->format('Y-m-d H:i:s')}') - INTERVAL '2 days') and date(starts) >= (date('{$show_end->format('Y-m-d H:i:s')}') - INTERVAL '2 days')
and modified_instance = false order by ends"; and modified_instance = false order by ends";
$stmt = $con->prepare("SELECT id, starts, ends FROM $stmt = $con->prepare("SELECT id, starts, ends FROM
{$CC_CONFIG['showInstances']} {$CC_CONFIG['showInstances']}
where (ends <= :show_end1 or starts <= :show_end2) where (ends <= :show_end1 or starts <= :show_end2)
and date(starts) >= (date(:show_end3) - INTERVAL '2 days') and date(starts) >= (date(:show_end3) - INTERVAL '2 days')

View File

@ -1873,7 +1873,7 @@ SELECT si.starts AS start_timestamp,
ends ends
FROM cc_show_instances si FROM cc_show_instances si
LEFT JOIN cc_show s LEFT JOIN cc_show s
ON si.instance_id = s.id ON si.show_id = s.id
WHERE si.show_id = s.id WHERE si.show_id = s.id
AND si.starts <= :timeNow1::timestamp AND si.starts <= :timeNow1::timestamp
AND si.ends > :timeNow2::timestamp AND si.ends > :timeNow2::timestamp
@ -1916,7 +1916,7 @@ SELECT si.starts AS start_timestamp,
ends ends
FROM cc_show_instances si FROM cc_show_instances si
LEFT JOIN cc_show s LEFT JOIN cc_show s
ON si.instance_id = s.id ON si.show_id = s.id
WHERE si.show_id = s.id WHERE si.show_id = s.id
AND si.starts > :timeNow1::timestamp - INTERVAL '2 days' AND si.starts > :timeNow1::timestamp - INTERVAL '2 days'
AND si.ends < :timeNow2::timestamp + INTERVAL '2 days' AND si.ends < :timeNow2::timestamp + INTERVAL '2 days'
@ -1930,7 +1930,7 @@ SQL;
$stmt->bindValue(':timeNow2', $p_timeNow); $stmt->bindValue(':timeNow2', $p_timeNow);
if ($stmt->execute()) { if ($stmt->execute()) {
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC); $rows = $stmt->fetchAll();
} else { } else {
$msg = implode(',', $stmt->errorInfo()); $msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg"); throw new Exception("Error: $msg");
@ -2055,7 +2055,7 @@ SELECT si.starts AS start_timestamp,
ends ends
FROM cc_show_instances si FROM cc_show_instances si
LEFT JOIN cc_show s LEFT JOIN cc_show s
ON si.instance_id = s.id ON si.show_id = s.id
WHERE si.show_id = s.id WHERE si.show_id = s.id
AND si.starts >= :timeStart::timestamp AND si.starts >= :timeStart::timestamp
AND si.starts < :timeEnd::timestamp AND si.starts < :timeEnd::timestamp

View File

@ -23,6 +23,7 @@ echo " 1. Install Packages"
echo "----------------------------------------------------" echo "----------------------------------------------------"
dist=`lsb_release -is` dist=`lsb_release -is`
code=`lsb_release -cs`
if [ "$dist" = "Debian" ]; then if [ "$dist" = "Debian" ]; then
set +e set +e
@ -51,8 +52,7 @@ php-pear php5-gd postgresql odbc-postgresql python libsoundtouch-ocaml \
libtaglib-ocaml libao-ocaml libmad-ocaml ecasound \ libtaglib-ocaml libao-ocaml libmad-ocaml ecasound \
libesd0 libportaudio2 libsamplerate0 rabbitmq-server patch \ libesd0 libportaudio2 libsamplerate0 rabbitmq-server patch \
php5-curl mpg123 monit python-virtualenv multitail libcamomile-ocaml-data \ php5-curl mpg123 monit python-virtualenv multitail libcamomile-ocaml-data \
libpulse0 vorbis-tools lsb-release lsof sudo mp3gain vorbisgain flac vorbis-tools \ libpulse0 vorbis-tools lsb-release lsof sudo mp3gain vorbisgain flac vorbis-tools
timeout
#install packages with --force-yes option (this is useful in the case #install packages with --force-yes option (this is useful in the case
#of Debian, where these packages are unauthorized) #of Debian, where these packages are unauthorized)
@ -68,6 +68,13 @@ else
apt-get -y install libzend-framework-php apt-get -y install libzend-framework-php
fi fi
if [ "$code" = "lucid" ]; then
apt-get -y install timeout
else
apt-get -y install coreutils
fi
#Install Sourcefabric's custom Liquidsoap debian package #Install Sourcefabric's custom Liquidsoap debian package
apt-get -y --force-yes install sourcefabric-keyring apt-get -y --force-yes install sourcefabric-keyring
apt-get -y --force-yes install liquidsoap apt-get -y --force-yes install liquidsoap

View File

@ -26,11 +26,12 @@ echo " 1. Install Packages"
echo "----------------------------------------------------" echo "----------------------------------------------------"
dist=`lsb_release -is` dist=`lsb_release -is`
code=`lsb_release -cs`
if [ "$dist" -eq "Debian" ]; then if [ "$dist" -eq "Debian" ]; then
grep "deb http://www.debian-multimedia.org squeeze main non-free" /etc/apt/sources.list grep "deb http://www.deb-multimedia.org squeeze main non-free" /etc/apt/sources.list
if [ "$?" -ne "0" ]; then if [ "$?" -ne "0" ]; then
echo "deb http://www.debian-multimedia.org squeeze main non-free" >> /etc/apt/sources.list echo "deb http://www.deb-multimedia.org squeeze main non-free" >> /etc/apt/sources.list
fi fi
fi fi
@ -42,8 +43,7 @@ php-pear php5-gd postgresql odbc-postgresql python libsoundtouch-ocaml \
libtaglib-ocaml libao-ocaml libmad-ocaml ecasound \ libtaglib-ocaml libao-ocaml libmad-ocaml ecasound \
libesd0 libportaudio2 libsamplerate0 rabbitmq-server patch \ libesd0 libportaudio2 libsamplerate0 rabbitmq-server patch \
php5-curl mpg123 monit python-virtualenv multitail libcamomile-ocaml-data \ php5-curl mpg123 monit python-virtualenv multitail libcamomile-ocaml-data \
libpulse0 vorbis-tools lsb-release lsof sudo mp3gain vorbisgain flac vorbis-tools \ libpulse0 vorbis-tools lsb-release lsof sudo mp3gain vorbisgain flac vorbis-tools
timeout
#install packages with --force-yes option (this is useful in the case #install packages with --force-yes option (this is useful in the case
#of Debian, where these packages are unauthorized) #of Debian, where these packages are unauthorized)
@ -58,6 +58,12 @@ else
apt-get -y install libzend-framework-php apt-get -y install libzend-framework-php
fi fi
if [ "$code" = "lucid" ]; then
apt-get -y install timeout
else
apt-get -y install coreutils
fi
# NGINX Config File # NGINX Config File
echo "----------------------------------------------------" echo "----------------------------------------------------"
echo "2.1 NGINX Config File" echo "2.1 NGINX Config File"