From 78b0dcedfc85e40930d79e96937c3c3cbdd1916c Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Fri, 7 Sep 2012 17:58:16 -0400 Subject: [PATCH 01/17] Added smartPrepareAndExecute. Warning: Test before using --- airtime_mvc/application/common/Database.php | 25 +++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/airtime_mvc/application/common/Database.php b/airtime_mvc/application/common/Database.php index 8793af03d..a90227ff6 100644 --- a/airtime_mvc/application/common/Database.php +++ b/airtime_mvc/application/common/Database.php @@ -29,4 +29,29 @@ class Application_Common_Database } 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); + } } From a479a11c8f86a6b9a6058d1cb78901fb5f4db38b Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Fri, 7 Sep 2012 18:23:14 -0400 Subject: [PATCH 02/17] Removed crazy handling of flac. --- airtime_mvc/application/models/StoredFile.php | 4 +++- python_apps/media-monitor2/media/monitor/pure.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index 9e6463ed9..312208af8 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -413,8 +413,10 @@ class Application_Model_StoredFile return "ogg"; } elseif ($mime == "audio/mp3" || $mime == "audio/mpeg") { return "mp3"; - } elseif ($mime == "audio/x/flac") { + } elseif ($mime == "audio/x-flac") { return "flac"; + } else { + throw new Exception("Unknown $mime"); } } diff --git a/python_apps/media-monitor2/media/monitor/pure.py b/python_apps/media-monitor2/media/monitor/pure.py index 3116fa3fd..9fe1b41df 100644 --- a/python_apps/media-monitor2/media/monitor/pure.py +++ b/python_apps/media-monitor2/media/monitor/pure.py @@ -244,7 +244,7 @@ def normalized_metadata(md, original_path): format_rules = { 'MDATA_KEY_TRACKNUMBER' : parse_int, '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], } From 35c8b50d96fc89dc6e6fc087f822f87aa64ff7f8 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Fri, 7 Sep 2012 18:23:55 -0400 Subject: [PATCH 03/17] cc-4347: PDO'd Show create --- airtime_mvc/application/models/Show.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index a41345065..38c6cbf91 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -1176,6 +1176,8 @@ SQL; ->delete(); } //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)) { for ($i=1; $i<=10; $i++) { if ($data['add_show_rebroadcast_date_'.$i]) { @@ -1189,10 +1191,21 @@ SQL; } elseif ($isRecorded && $data['add_show_rebroadcast'] && ($repeatType == -1)) { for ($i=1; $i<=10; $i++) { if ($data['add_show_rebroadcast_date_absolute_'.$i]) { - $con = Propel::getConnection(CcShowPeer::DATABASE_NAME); - $sql = "SELECT date '{$data['add_show_rebroadcast_date_absolute_'.$i]}' - date '{$data['add_show_start_date']}' "; - $r = $con->query($sql); - $offset_days = $r->fetchColumn(0); + //$con = Propel::getConnection(CcShowPeer::DATABASE_NAME); + //$sql = "SELECT date '{$data['add_show_rebroadcast_date_absolute_'.$i]}' - date '{$data['add_show_start_date']}' "; + $sql = << + $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->setDbDayOffset($offset_days." days"); From 99a3a8deab67e4c913766068e378ef327e8165be Mon Sep 17 00:00:00 2001 From: Daniel James Date: Mon, 10 Sep 2012 11:17:17 +0100 Subject: [PATCH 04/17] Added depedency on pwgen --- debian/control | 1 + 1 file changed, 1 insertion(+) diff --git a/debian/control b/debian/control index 61cd5dc1b..6e9ae3dee 100644 --- a/debian/control +++ b/debian/control @@ -37,6 +37,7 @@ Depends: apache2, php-pear, php5-pgsql, python, + pwgen, rabbitmq-server, sudo, sysv-rc, From a3d4b8c722c35dcd50611b2c17350988bc98a031 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 10 Sep 2012 11:05:30 -0400 Subject: [PATCH 05/17] Todo for consistency. --- .../application/models/ShowInstance.php | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/airtime_mvc/application/models/ShowInstance.php b/airtime_mvc/application/models/ShowInstance.php index afbacdadf..906f59ff9 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -167,26 +167,33 @@ class Application_Model_ShowInstance $con = Propel::getConnection(); $instance_id = $this->getShowInstanceId(); - $sql = "SELECT starts from cc_schedule" - ." WHERE instance_id = $instance_id" - ." ORDER BY starts" - ." LIMIT 1"; - - $scheduleStarts = $con->query($sql)->fetchColumn(0); + $sql = << $instance_id ), 'column' ); if ($scheduleStarts) { $scheduleStartsEpoch = strtotime($scheduleStarts); - $showStartsEpoch = strtotime($this->getShowInstanceStart()); + $showStartsEpoch = strtotime($this->getShowInstanceStart()); $diff = $showStartsEpoch - $scheduleStartsEpoch; if ($diff != 0) { - $sql = "UPDATE cc_schedule" - ." SET starts = starts + INTERVAL '$diff' second," - ." ends = ends + INTERVAL '$diff' second" - ." WHERE instance_id = $instance_id"; - - $con->exec($sql); + $sql = << $diff, + ':diff2' => $diff, + ':instanceId' => $instance_id ), 'execute'); } } Application_Model_RabbitMq::PushSchedule(); From 737c3fcbae84702bf1134b8e51df49ca3ca9ee83 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 10 Sep 2012 11:06:11 -0400 Subject: [PATCH 06/17] Todo for consistency. --- airtime_mvc/application/models/ShowInstance.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/airtime_mvc/application/models/ShowInstance.php b/airtime_mvc/application/models/ShowInstance.php index 906f59ff9..1e71510d7 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -22,6 +22,8 @@ class Application_Model_ShowInstance return $this->_showInstance->getDbShowId(); } + /* TODO: A little inconsistent because other models have a getId() method + to get PK --RG */ public function getShowInstanceId() { return $this->_instanceId; From 57aae73074309179fb26e4b3e0f760263f69ac6b Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 10 Sep 2012 11:06:34 -0400 Subject: [PATCH 07/17] cc-4347: PDO'd: GetLastShowInstance --- .../application/models/ShowInstance.php | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/airtime_mvc/application/models/ShowInstance.php b/airtime_mvc/application/models/ShowInstance.php index 1e71510d7..ef2521ad5 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -754,22 +754,17 @@ SQL; public static function GetLastShowInstance($p_timeNow) { - global $CC_CONFIG; - $con = Propel::getConnection(); + $sql = << $p_timeNow ), 'column' ); - $sql = "SELECT si.id" - ." 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; - } + return ($id ? new Application_Model_ShowInstance($id) : null ); } public static function GetCurrentShowInstance($p_timeNow) From 8c3be7393a7336552140a81171fc6dfbae61f823 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 10 Sep 2012 11:17:45 -0400 Subject: [PATCH 08/17] cc-4347: GetCurrentShowInstance got PDO nuked. --- .../application/models/ShowInstance.php | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/airtime_mvc/application/models/ShowInstance.php b/airtime_mvc/application/models/ShowInstance.php index ef2521ad5..d3ee829ac 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -769,29 +769,26 @@ SQL; public static function GetCurrentShowInstance($p_timeNow) { - global $CC_CONFIG; - $con = Propel::getConnection(); - /* Orderby si.starts descending, because in some cases * we can have multiple shows overlapping each other. In * this case, the show that started later is the one that * is actually playing, and so this is the one we want. */ - $sql = "SELECT si.id" - ." FROM $CC_CONFIG[showInstances] si" - ." WHERE si.starts <= TIMESTAMP '$p_timeNow'" - ." AND si.ends > TIMESTAMP '$p_timeNow'" - ." AND si.modified_instance = 'f'" - ." ORDER BY si.starts DESC" - ." LIMIT 1"; + $sql = << :timeNow2::TIMESTAMP + AND si.modified_instance = 'f' +ORDER BY si.starts DESC LIMIT 1 +SQL; - $id = $con->query($sql)->fetchColumn(0); - if ($id) { - return new Application_Model_ShowInstance($id); - } else { - return null; - } + $id = Application_Common_Database( $sql, array( + ':timeNow1' => $p_timeNow, + ':timeNow2' => $p_timeNow ), 'column'); + + return ( $id ? new Application_Model_ShowInstance($id) : null ); } public static function GetNextShowInstance($p_timeNow) From de86b904a5ba16fc98422d8c159a788fc74be677 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 10 Sep 2012 11:25:21 -0400 Subject: [PATCH 09/17] Fixed extra cast. --- airtime_mvc/application/models/Show.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 38c6cbf91..8214f4c03 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -1643,7 +1643,7 @@ SQL; $start_string = $start_timestamp->format("Y-m-d H:i:s"); $end_string = $end_timestamp->format("Y-m-d H:i:s"); 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)"; return Application_Common_Database::prepareAndExecute( $sql, From 53de942c2b393df1fbaed3253e1868a4f43b8651 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 10 Sep 2012 11:25:44 -0400 Subject: [PATCH 10/17] cc-4347: GetNextShowInstance PDO'd. --- .../application/models/ShowInstance.php | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/airtime_mvc/application/models/ShowInstance.php b/airtime_mvc/application/models/ShowInstance.php index d3ee829ac..238b08f27 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -793,22 +793,17 @@ SQL; public static function GetNextShowInstance($p_timeNow) { - global $CC_CONFIG; - $con = Propel::getConnection(); - - $sql = "SELECT si.id" - ." FROM $CC_CONFIG[showInstances] si" - ." WHERE si.starts > TIMESTAMP '$p_timeNow'" - ." AND si.modified_instance = 'f'" - ." ORDER BY si.starts" - ." LIMIT 1"; - - $id = $con->query($sql)->fetchColumn(0); - if ($id) { - return new Application_Model_ShowInstance($id); - } else { - return null; - } + $sql = << :timeNow::TIMESTAMP +AND si.modified_instance = 'f' +ORDER BY si.starts +LIMIT 1 +SQL; + $id = Application_Common_Database::prepareAndExecute( $sql, + array( 'timeNow' => $p_timeNow ), 'column' ); + return ( $id ? new Application_Model_ShowInstance($id) : null ); } // returns number of show instances that ends later than $day From 375e89169e7c4f74e54fc5025ae84d1f26d42cde Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 10 Sep 2012 11:27:39 -0400 Subject: [PATCH 11/17] Removed code duplication --- airtime_mvc/application/models/ShowInstance.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/airtime_mvc/application/models/ShowInstance.php b/airtime_mvc/application/models/ShowInstance.php index 238b08f27..1c8c66783 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -833,10 +833,6 @@ SQL; public function isRepeating() { - if ($this->getShow()->isRepeating()) { - return true; - } else { - return false; - } + return $this->getShow()->isRepeating(); } } From dcf3b4c3de43ec9f4695f3d01ac6d60c79ce1cff Mon Sep 17 00:00:00 2001 From: James Date: Mon, 10 Sep 2012 11:28:35 -0400 Subject: [PATCH 12/17] CC-4383: Fatal error in phone_home_stat script (2.2.0 dev) - fixed --- utils/phone_home_stat.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/utils/phone_home_stat.php b/utils/phone_home_stat.php index f720f0dd0..d01a736c1 100644 --- a/utils/phone_home_stat.php +++ b/utils/phone_home_stat.php @@ -35,6 +35,14 @@ get_include_path(), 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/StoredFile.php'); require_once($CC_CONFIG['phpDir'].'/application/models/Playlist.php'); From e2c2f67fbb51882101e7e5b46b3e44abf26b216b Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 10 Sep 2012 11:29:28 -0400 Subject: [PATCH 13/17] cc-4347: GetShowInstanceCount() pdo'd --- airtime_mvc/application/models/ShowInstance.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/airtime_mvc/application/models/ShowInstance.php b/airtime_mvc/application/models/ShowInstance.php index 1c8c66783..c19d8c3b7 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -809,11 +809,13 @@ SQL; // returns number of show instances that ends later than $day public static function GetShowInstanceCount($day) { - global $CC_CONFIG; - $con = Propel::getConnection(); - $sql = "SELECT count(*) as cnt FROM $CC_CONFIG[showInstances] WHERE ends < '$day'"; - - return $con->query($sql)->fetchColumn(0); + $sql = << $day ), 'column' ); } // this returns end timestamp of all shows that are in the range and has live DJ set up From 3df4c8d65ad78abd2b956aef79d033c8674eee87 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 10 Sep 2012 11:39:22 -0400 Subject: [PATCH 14/17] cc-4347: deleteRebroadcasts and GetEndTimeOfNextShowWithLiveDJ pdo'd --- .../application/models/ShowInstance.php | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/airtime_mvc/application/models/ShowInstance.php b/airtime_mvc/application/models/ShowInstance.php index c19d8c3b7..03a4d60a2 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -36,17 +36,17 @@ class Application_Model_ShowInstance public function deleteRebroadcasts() { - $con = Propel::getConnection(); - $timestamp = gmdate("Y-m-d H:i:s"); $instance_id = $this->getShowInstanceId(); - - $sql = "DELETE FROM cc_show_instances" - ." WHERE starts > TIMESTAMP '$timestamp'" - ." AND instance_id = $instance_id" - ." AND rebroadcast = 1"; - - $con->exec($sql); + $sql = << :timestamp::TIMESTAMP +AND instance_id = :instanceId +AND rebroadcast = 1; +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 @@ -821,16 +821,19 @@ SQL; // 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) { - global $CC_CONFIG; - $con = Propel::getConnection(); - - $sql = "SELECT ends - FROM cc_show_instances as si - JOIN cc_show as sh ON si.show_id = sh.id - WHERE si.ends > '$p_startTime' and si.ends < '$p_endTime' and (sh.live_stream_using_airtime_auth or live_stream_using_custom_auth) - ORDER BY si.ends"; - - return $con->query($sql)->fetchAll(); + $sql = << :startTime::TIMESTAMP + AND si.ends < :endTime::TIMESTAMP + AND (sh.live_stream_using_airtime_auth + OR live_stream_using_custom_auth) +ORDER BY si.ends"; +SQL; + return Application_Common_Database::prepareAndExecute( $sql, array( + ':startTime' => $p_startTime, + ':endTime' => $p_endTime), 'all'); } public function isRepeating() From a0b3742758e065e2e697c0ac33ba2dae5c27145e Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 10 Sep 2012 11:49:56 -0400 Subject: [PATCH 15/17] cc-4347: resizeShow pdo'd --- .../application/models/ShowInstance.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/airtime_mvc/application/models/ShowInstance.php b/airtime_mvc/application/models/ShowInstance.php index 03a4d60a2..825516ea6 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -324,11 +324,6 @@ SQL; 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) { $con = Propel::getConnection(); @@ -372,9 +367,17 @@ SQL; //must update length of all rebroadcast instances. if ($this->isRecorded()) { - $sql = "UPDATE cc_show_instances SET ends = (ends + interval '{$deltaDay} days' + interval '{$hours}:{$mins}') - WHERE rebroadcast = 1 AND instance_id = {$this->_instanceId}"; - $con->exec($sql); + $sql = << "$deltaDay days", + ':interval' => "$hours:$mins", + ':instanceId' => $this->_instanceId ), 'execute'); + } $this->setShowEnd($new_ends); From 8340db3ce91d326a563506627cbdf8144274b67d Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 10 Sep 2012 11:53:22 -0400 Subject: [PATCH 16/17] Added error handing todo --- airtime_mvc/application/models/ShowInstance.php | 1 + 1 file changed, 1 insertion(+) diff --git a/airtime_mvc/application/models/ShowInstance.php b/airtime_mvc/application/models/ShowInstance.php index 825516ea6..c4aa49611 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -360,6 +360,7 @@ SQL; $overlap = Application_Model_Show::getShows($utcStartDateTime, $utcEndDateTime); if (count($overlap) > 0) { + // TODO : fix ghetto error handling -- RG return "Should not overlap shows"; } } From 567a8a2635a77e7fc1244946fc761f7b0545a179 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 10 Sep 2012 12:04:33 -0400 Subject: [PATCH 17/17] cc-4347: Fixed typo --- airtime_mvc/application/models/ShowInstance.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airtime_mvc/application/models/ShowInstance.php b/airtime_mvc/application/models/ShowInstance.php index c4aa49611..a53bb3a8a 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -833,7 +833,7 @@ WHERE si.ends > :startTime::TIMESTAMP AND si.ends < :endTime::TIMESTAMP AND (sh.live_stream_using_airtime_auth OR live_stream_using_custom_auth) -ORDER BY si.ends"; +ORDER BY si.ends SQL; return Application_Common_Database::prepareAndExecute( $sql, array( ':startTime' => $p_startTime,