From e7e8e36da37ee159aa568ce0541315132fbfdcda Mon Sep 17 00:00:00 2001 From: Daniel James <daniel@64studio.com> Date: Fri, 7 Sep 2012 10:52:10 +0100 Subject: [PATCH 01/24] Add dependency on timeout package for Ubuntu Lucid only Fix Description line so it is Debian/Ubuntu compliant --- debian/control | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/debian/control b/debian/control index c4e5663e9..61cd5dc1b 100644 --- a/debian/control +++ b/debian/control @@ -41,6 +41,7 @@ Depends: apache2, sudo, sysv-rc, tar (>= 1.22), + coreutils (>= 7.5) | timeout, unzip, vorbis-tools, zendframework | libzend-framework-php, @@ -48,7 +49,7 @@ Depends: apache2, Recommends: icecast2 Suggests: airtime-audio-samples, alsa-utils -Description: The open radio software for scheduling and remote station management. +Description: open radio software for scheduling and remote station management. Airtime is an open source application that provides remote automation of a radio station. . From d805995e72e4be6b1780c9b51d1a6c163af093bc Mon Sep 17 00:00:00 2001 From: Rudi Grinberg <rudi.grinberg@sourcefabric.org> Date: Fri, 7 Sep 2012 11:12:26 -0400 Subject: [PATCH 02/24] cc-4347: ~~~~PDO~~~~~~ --- airtime_mvc/application/models/Show.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index afe6e817d..a684aa62f 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -233,14 +233,16 @@ class Application_Model_Show AND ((CAST(duration AS interval) + interval '{$deltaDay} days' + interval '{$hours}:{$mins}') <= interval '24:00')"; $sql_gen = <<<SQL -UPDATE cc_show_instances +UPDATE cc_show_instances SET ends = (ends + interval :deltaDay1 + interval :interval1) -WHERE (show_id = :show_id1 AND ends > :current_timestamp1) -AND ((ends + interval :deltaDay2 + interval :interval2 - starts) <= interval '24:00') +WHERE (show_id = :show_id1 + AND ends > :current_timestamp1) + AND ((ends + interval :deltaDay2 + interval :interval2 - starts) <= interval '24:00') -UPDATE cc_show_days SET duration = (CAST(duration AS interval) + interval :deltaDay3 + interval :interval3) +UPDATE cc_show_days +SET duration = (CAST(duration AS interval) + interval :deltaDay3 + interval :interval3) WHERE show_id = :show_id2 -AND ((CAST(duration AS interval) + interval :deltaDay4 + interval :interval4) <= interval '24:00') + AND ((CAST(duration AS interval) + interval :deltaDay4 + interval :interval4) <= interval '24:00') SQL; Application_Common_Database::prepareAndExecute($sql_gen, @@ -308,7 +310,9 @@ SQL; ->findOne(); if (is_null($showInstancesRow)) { - $sql = "DELETE FROM cc_show WHERE id = {$this->_showId}"; + $sql = "DELETE FROM cc_show WHERE id = :show_id"; + Application_Common_Database::prepareAndExecute( + $sql, array( 'show_id' => $this->_showId ), "execute"); $con->exec($sql); } @@ -805,10 +809,10 @@ SQL; $sql = <<<SQL -UPDATE cc_show_instances +UPDATE cc_show_instances SET ends = starts + :add_show_duration::INTERVAL WHERE show_id = :show_id -AND ends > :timestamp::TIMESTAMP + AND ends > :timestamp::TIMESTAMP SQL; From c28f3af9cff249900ce6843be7a876157ac7a4f6 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg <rudi.grinberg@sourcefabric.org> Date: Fri, 7 Sep 2012 11:18:10 -0400 Subject: [PATCH 03/24] removed unused code. reformatted some comments. --- airtime_mvc/application/models/Show.php | 42 ++++++------------------- 1 file changed, 10 insertions(+), 32 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index a684aa62f..5456b7776 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -178,22 +178,21 @@ class Application_Model_Show ->filterByDbShowId($this->_showId) ->find($con); - /* Check if the show being resized and any of its repeats - * overlap with other scheduled shows - */ + /* Check if the show being resized and any of its repeats * overlap + with other scheduled shows */ foreach ($showInstances as $si) { $startsDateTime = new DateTime($si->getDbStarts(), new DateTimeZone("UTC")); - $endsDateTime = new DateTime($si->getDbEnds(), new DateTimeZone("UTC")); + $endsDateTime = new DateTime($si->getDbEnds(), new DateTimeZone("UTC")); - /* The user is moving the show on the calendar from the perspective of local time. - * incase a show is moved across a time change border offsets should be added to the local - * timestamp and then converted back to UTC to avoid show time changes - */ + /* The user is moving the show on the calendar from the perspective + of local time. * incase a show is moved across a time change + border offsets should be added to the local * timestamp and + then converted back to UTC to avoid show time changes */ $startsDateTime->setTimezone(new DateTimeZone(date_default_timezone_get())); $endsDateTime->setTimezone(new DateTimeZone(date_default_timezone_get())); $newStartsDateTime = Application_Model_ShowInstance::addDeltas($startsDateTime, $deltaDay, $deltaMin); - $newEndsDateTime = Application_Model_ShowInstance::addDeltas($endsDateTime, $deltaDay, $deltaMin); + $newEndsDateTime = Application_Model_ShowInstance::addDeltas($endsDateTime, $deltaDay, $deltaMin); //convert our new starts/ends to UTC. $newStartsDateTime->setTimezone(new DateTimeZone("UTC")); @@ -208,30 +207,12 @@ class Application_Model_Show } $hours = $deltaMin/60; - if ($hours > 0) { - $hours = floor($hours); - } else { - $hours = ceil($hours); - } - - $mins = abs($deltaMin%60); + $hours = ($hours > 0) ? floor($hours) : ceil($hours); + $mins = abs($deltaMin % 60); //current timesamp in UTC. $current_timestamp = gmdate("Y-m-d H:i:s"); - //update all cc_show_instances that are in the future. - $sql = "UPDATE cc_show_instances - SET ends = (ends + interval '{$deltaDay} days' + interval '{$hours}:{$mins}') - WHERE (show_id = {$this->_showId} AND ends > '$current_timestamp') - AND ((ends + interval '{$deltaDay} days' + interval '{$hours}:{$mins}' - starts) <= interval '24:00');"; - - //update cc_show_days so future shows can be created with the new duration. - //only setting new duration if it is less than or equal to 24 hours. - $sql = $sql . " - UPDATE cc_show_days SET duration = (CAST(duration AS interval) + interval '{$deltaDay} days' + interval '{$hours}:{$mins}') - WHERE show_id = {$this->_showId} - AND ((CAST(duration AS interval) + interval '{$deltaDay} days' + interval '{$hours}:{$mins}') <= interval '24:00')"; - $sql_gen = <<<SQL UPDATE cc_show_instances SET ends = (ends + interval :deltaDay1 + interval :interval1) @@ -260,9 +241,6 @@ SQL; ':interval4' => "$hours:$mins" ), "execute"); - //do both the queries at once. - //$con->exec($sql); - $con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME); $con->beginTransaction(); From f61463b8baa82c49b0dbd6a5fe7f9d05a9412745 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg <rudi.grinberg@sourcefabric.org> Date: Fri, 7 Sep 2012 11:20:23 -0400 Subject: [PATCH 04/24] premature optimization --- airtime_mvc/application/models/Show.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 5456b7776..b1fb85a1c 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -180,9 +180,11 @@ class Application_Model_Show /* Check if the show being resized and any of its repeats * overlap with other scheduled shows */ + $utc = new DateTimeZone("UTC"); + foreach ($showInstances as $si) { - $startsDateTime = new DateTime($si->getDbStarts(), new DateTimeZone("UTC")); - $endsDateTime = new DateTime($si->getDbEnds(), new DateTimeZone("UTC")); + $startsDateTime = new DateTime($si->getDbStarts(), $utc); + $endsDateTime = new DateTime($si->getDbEnds(), $utc); /* The user is moving the show on the calendar from the perspective of local time. * incase a show is moved across a time change @@ -195,11 +197,12 @@ class Application_Model_Show $newEndsDateTime = Application_Model_ShowInstance::addDeltas($endsDateTime, $deltaDay, $deltaMin); //convert our new starts/ends to UTC. - $newStartsDateTime->setTimezone(new DateTimeZone("UTC")); - $newEndsDateTime->setTimezone(new DateTimeZone("UTC")); + $newStartsDateTime->setTimezone($utc); + $newEndsDateTime->setTimezone($utc); + + $overlapping = Application_Model_Schedule::checkOverlappingShows( + $newStartsDateTime, $newEndsDateTime, true, $si->getDbId()); - $overlapping = Application_Model_Schedule::checkOverlappingShows($newStartsDateTime, - $newEndsDateTime, true, $si->getDbId()); if ($overlapping) { return "Cannot schedule overlapping shows.\nNote: Resizing a repeating show ". "affects all of its repeats."; From 92682b9f895ca3bc7f1079cb2344e42cc002c8e3 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg <rudi.grinberg@sourcefabric.org> Date: Fri, 7 Sep 2012 11:23:18 -0400 Subject: [PATCH 05/24] Added TODO about unused code --- airtime_mvc/application/models/Show.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index b1fb85a1c..fcadb9ee4 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -84,6 +84,10 @@ class Application_Model_Show return $show->getDbUrl(); } + /*TODO : This method is not actually used anywhere as far as I can tell. We + can safely remove it and probably many other superfluous methods. + --RG*/ + public function setUrl($p_url) { $show = CcShowQuery::create()->findPK($this->_showId); From 22a250b5d280018cccc4ea564037d83bd94efa85 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg <rudi.grinberg@sourcefabric.org> Date: Fri, 7 Sep 2012 11:52:57 -0400 Subject: [PATCH 06/24] cc-4347: PDOOO --- airtime_mvc/application/models/Show.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index fcadb9ee4..293178d36 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -355,14 +355,22 @@ SQL; $uncheckedDaysImploded = implode(",", $daysRemovedUTC); $showId = $this->getId(); + $esc_uncheckedDays = pg_escape_string($uncheckedDaysImploded); $timestamp = gmdate("Y-m-d H:i:s"); - $sql = "DELETE FROM cc_show_instances" - ." WHERE EXTRACT(DOW FROM starts) IN ($uncheckedDaysImploded)" - ." AND starts > TIMESTAMP '$timestamp'" - ." AND show_id = $showId"; + $sql = <<<SQL +DELETE +FROM cc_show_instances +WHERE EXTRACT(DOW FROM starts) IN ($esc_uncheckedDays) + AND starts > :timestamp::TIMESTAMP + AND show_id = :showId +SQL; - $con->exec($sql); + Application_Common_Database::prepareAndExecute( $sql, + array( + ":timestamp" => $timestamp, + ":showId" => $showId, + ), "execute"); } /** From 2a00e58610db78881e593a176edc8d8a4535492e Mon Sep 17 00:00:00 2001 From: Rudi Grinberg <rudi.grinberg@sourcefabric.org> Date: Fri, 7 Sep 2012 11:58:57 -0400 Subject: [PATCH 07/24] cc-4347: PDO like a boss. --- airtime_mvc/application/models/Show.php | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 293178d36..0fa4fb3cc 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -419,17 +419,20 @@ SQL; */ public function getRebroadcastsAbsolute() { - $con = Propel::getConnection(); + $sql = <<<SQL +SELECT starts +FROM cc_show_instances +WHERE instance_id = + (SELECT id + FROM cc_show_instances + WHERE show_id = :showId + ORDER BY starts LIMIT 1) + AND rebroadcast = 1 +ORDER BY starts +SQL; - $showId = $this->getId(); - - $sql = "SELECT starts FROM cc_show_instances " - ."WHERE instance_id = (SELECT id FROM cc_show_instances WHERE show_id = $showId ORDER BY starts LIMIT 1) AND rebroadcast = 1 " - ."ORDER BY starts"; - - //Logging::info($sql); - - $rebroadcasts = $con->query($sql)->fetchAll(); + $rebroadcasts = Application_Common_Database::prepareAndExecute( $sql, + array( 'showId' => $this->getId() ), 'all' ); $rebroadcastsLocal = array(); //get each rebroadcast show in cc_show_instances, convert to current timezone to get start date/time. From cfe0d7aa0c50e7dbd32166a40edfd34c327f809e Mon Sep 17 00:00:00 2001 From: Rudi Grinberg <rudi.grinberg@sourcefabric.org> Date: Fri, 7 Sep 2012 12:05:48 -0400 Subject: [PATCH 08/24] Unrelated refactorings of Show.php. Added TODO for more later work. --- airtime_mvc/application/models/Show.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 0fa4fb3cc..dc88e151d 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -436,13 +436,21 @@ SQL; $rebroadcastsLocal = array(); //get each rebroadcast show in cc_show_instances, convert to current timezone to get start date/time. + /*TODO: refactor the following code to get rid of the $i temporary + variable. -- RG*/ $i = 0; - foreach ($rebroadcasts as $show) { - $startDateTime = new DateTime($show["starts"], new DateTimeZone("UTC")); - $startDateTime->setTimezone(new DateTimeZone(date_default_timezone_get())); - $rebroadcastsLocal[$i]["start_date"] = $startDateTime->format("Y-m-d"); - $rebroadcastsLocal[$i]["start_time"] = $startDateTime->format("H:i"); + $utc = new DateTimeZone("UTC"); + $dtz = new DateTimeZone( date_default_timezone_get() ); + + foreach ($rebroadcasts as $show) { + $startDateTime = new DateTime($show["starts"], $utc); + $startDateTime->setTimezone($dtz); + + $rebroadcastsLocal[$i]["start_date"] = + $startDateTime->format("Y-m-d"); + $rebroadcastsLocal[$i]["start_time"] = + $startDateTime->format("H:i"); $i = $i + 1; } From 23ccd75290a1373f5ea6c17588c4003d0aac2d81 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg <rudi.grinberg@sourcefabric.org> Date: Fri, 7 Sep 2012 12:10:07 -0400 Subject: [PATCH 09/24] cc-4347: PDO getRbroadcastsRelative() --- airtime_mvc/application/models/Show.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index dc88e151d..0323ac330 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -468,14 +468,15 @@ SQL; */ public function getRebroadcastsRelative() { - $con = Propel::getConnection(); - - $showId = $this->getId(); - $sql = "SELECT day_offset, start_time FROM cc_show_rebroadcast " - ."WHERE show_id = $showId " - ."ORDER BY day_offset"; - - return $con->query($sql)->fetchAll(); + $sql = <<<SQL +SELECT day_offset, + start_time +FROM cc_show_rebroadcast +WHERE show_id = :showId +ORDER BY day_offset +SQL; + return Application_Common_Database::prepareAndExecute( $sql, + array( ':showId' => $this->getId() ), 'all' ); } /** From 727769b3761b8c834263f4c0ba404c981790d180 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg <rudi.grinberg@sourcefabric.org> Date: Fri, 7 Sep 2012 12:18:13 -0400 Subject: [PATCH 10/24] cc-4347: PDO getRepeatingDate() --- airtime_mvc/application/models/Show.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 0323ac330..56ef05405 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -528,15 +528,18 @@ SQL; */ public function getRepeatingEndDate() { - $con = Propel::getConnection(); + $sql = <<<SQL +SELECT last_show +FROM cc_show_days +WHERE show_id = :showId +ORDER BY last_show DESC +SQL; - $showId = $this->getId(); - $sql = "SELECT last_show FROM cc_show_days" - ." WHERE show_id = $showId" - ." ORDER BY last_show DESC"; - - $query = $con->query($sql)->fetchColumn(0); + $query = Application_Common_Database::prepareAndExecute( $sql, + array( 'showId' => $this->getId() ), 'column' ); + /* TODO: Why return empty string instead of false? very confusing --RG + */ return ($query !== false) ? $query : ""; } From ad776ff8f36eab6436ed8a6a2d9cb18a940a469f Mon Sep 17 00:00:00 2001 From: Rudi Grinberg <rudi.grinberg@sourcefabric.org> Date: Fri, 7 Sep 2012 12:22:49 -0400 Subject: [PATCH 11/24] cc-4347: PDO deleteAllInstances() --- airtime_mvc/application/models/Show.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 56ef05405..84a79528c 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -555,16 +555,15 @@ SQL; */ public function deleteAllInstances() { - $con = Propel::getConnection(); - - $timestamp = gmdate("Y-m-d H:i:s"); - - $showId = $this->getId(); - $sql = "DELETE FROM cc_show_instances" - ." WHERE starts > TIMESTAMP '$timestamp'" - ." AND show_id = $showId"; - - $con->exec($sql); + $sql = <<<SQL +DELETE +FROM cc_show_instances +WHERE starts > :timestamp::TIMESTAMP + AND show_id = :showId +SQL; + Application_Common_Database::prepareAndExecute( $sql, + array( ':timestamp' => gmdate("Y-m-d H:i:s"), + ':showId' => $this->getId()), 'execute'); } /** From efb35dd9d6285749657d27a089bc0c3cf43d539c Mon Sep 17 00:00:00 2001 From: Rudi Grinberg <rudi.grinberg@sourcefabric.org> Date: Fri, 7 Sep 2012 12:29:42 -0400 Subject: [PATCH 12/24] cc-4347: PDO'd deleteAllRebroadcasts() --- airtime_mvc/application/models/Show.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 84a79528c..06b6aadf3 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -572,15 +572,16 @@ SQL; */ public function deleteAllRebroadcasts() { - $con = Propel::getConnection(); - - $timestamp = gmdate("Y-m-d H:i:s"); - - $showId = $this->getId(); - $sql = "DELETE FROM cc_show_instances" - ." WHERE starts > TIMESTAMP '$timestamp'" - ." AND show_id = $showId" - ." AND rebroadcast = 1"; + $sql = <<<SQL +DELETE +FROM cc_show_instances +WHERE starts > :timestamp::TIMESTAMP + AND show_id :showId + AND rebroadcast 1 +SQL; + Application_Common_Database::prepareAndExecute( $sql, + array( ':showId' => $this->getId(), + ':timestamp' => gmdate("Y-m-d H:i:s")), 'execute'); $con->exec($sql); } From 82f267310e66d8923a8a99a9e9ff9b755c3174f2 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg <rudi.grinberg@sourcefabric.org> Date: Fri, 7 Sep 2012 14:18:40 -0400 Subject: [PATCH 13/24] cc-4347: Undid refactoring --- airtime_mvc/application/models/Show.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 06b6aadf3..dbca3ec4c 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -184,11 +184,10 @@ class Application_Model_Show /* Check if the show being resized and any of its repeats * overlap with other scheduled shows */ - $utc = new DateTimeZone("UTC"); foreach ($showInstances as $si) { - $startsDateTime = new DateTime($si->getDbStarts(), $utc); - $endsDateTime = new DateTime($si->getDbEnds(), $utc); + $startsDateTime = new DateTime($si->getDbStarts(), new DateTimeZone("UTC")); + $endsDateTime = new DateTime($si->getDbEnds(), new DateTimeZone("UTC")); /* The user is moving the show on the calendar from the perspective of local time. * incase a show is moved across a time change @@ -822,7 +821,6 @@ SET ends = starts + :add_show_duration::INTERVAL WHERE show_id = :show_id AND ends > :timestamp::TIMESTAMP SQL; - Application_Common_Database::prepareAndExecute( $sql, array( ':add_show_duration' => $p_data['add_show_duration'], From 5ee24ceb2303b98fdb2032803edb139660d41cec Mon Sep 17 00:00:00 2001 From: Rudi Grinberg <rudi.grinberg@sourcefabric.org> Date: Fri, 7 Sep 2012 14:30:59 -0400 Subject: [PATCH 14/24] cc-4347: PDO. getAllFutureInstanceIds() --- airtime_mvc/application/models/Show.php | 34 ++++++++++--------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index dbca3ec4c..edee46359 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -663,8 +663,6 @@ SQL; $stmt->bindParam(':showId', $showId); $stmt->execute(); - //$query = $con->query($sql); - if (!$stmt) { return ""; } @@ -770,25 +768,20 @@ SQL; */ public function getAllFutureInstanceIds() { - $con = Propel::getConnection(); + $sql = <<<SQL +SELECT id +FROM cc_show_instances +WHERE show_id :showId + AND starts > :timestamp::TIMESTAMP + AND modified_instance != TRUE +SQL; + $rows = Application_Common_Database::prepareAndExecute($sql, + array( ':showId' => $this->getId(), + ':timestamp' => gmdate("Y-m-d H:i:s")), "all"); - $date = new Application_Common_DateHelper; - $timestamp = $date->getTimestamp(); - - $showId = $this->getId(); - $sql = "SELECT id from cc_show_instances" - ." WHERE show_id = $showId" - ." AND starts > TIMESTAMP '$timestamp'" - ." AND modified_instance != TRUE"; - - $rows = $con->query($sql)->fetchAll(); - - $instance_ids = array(); - foreach ($rows as $row) { - $instance_ids[] = $row["id"]; - } - - return $instance_ids; + return array_map( function($i) { + return $i['id']; + }, $rows); } /* Called when a show's duration is changed (edited). @@ -2086,7 +2079,6 @@ SQL; throw new Exception("Error: $msg"); } - return $rows; } /** From 49a85afc06a3c5231d1ef64cfb4247144efa22dd Mon Sep 17 00:00:00 2001 From: Rudi Grinberg <rudi.grinberg@sourcefabric.org> Date: Fri, 7 Sep 2012 14:33:08 -0400 Subject: [PATCH 15/24] Refactor --- airtime_mvc/application/models/Show.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index edee46359..7b56569db 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -877,14 +877,11 @@ SQL; public function getShowDays() { - $showDays = CcShowDaysQuery::create()->filterByDbShowId($this->getId())->find(); - - $days = array(); - foreach ($showDays as $showDay) { - array_push($days, $showDay->getDbDay()); - } - - return $days; + $showDays = CcShowDaysQuery::create()->filterByDbShowId( + $this->getId())->find(); + return array_map( function($showDay) { + return $showDay->getDbDay(); + }, $showDays); } /* Only used for shows that aren't repeating. From 27c1361fbb190d1c54ed0a0a88b92731a058871b Mon Sep 17 00:00:00 2001 From: Rudi Grinberg <rudi.grinberg@sourcefabric.org> Date: Fri, 7 Sep 2012 15:12:46 -0400 Subject: [PATCH 16/24] Small refactoring to use getter instead of accessing private variable. --- airtime_mvc/application/models/Show.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 7b56569db..6a17969b0 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -911,7 +911,7 @@ SQL; public function getLiveStreamInfo() { $info = array(); - if ($this->_showId == null) { + if ($this->getId() == null) { return $info; } else { $ccShow = CcShowQuery::create()->findPK($this->_showId); @@ -920,7 +920,6 @@ SQL; $info['cb_custom_auth'] = $ccShow->getDbLiveStreamUsingCustomAuth(); $info['custom_username'] = $ccShow->getDbLiveStreamUser(); $info['custom_password'] = $ccShow->getDbLiveStreamPass(); - return $info; } } From 26a3e35de00ef5852fa0691bb2e1a4e975ab55f2 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg <rudi.grinberg@sourcefabric.org> Date: Fri, 7 Sep 2012 15:14:33 -0400 Subject: [PATCH 17/24] Refactored getMaxLengths() --- airtime_mvc/application/models/Show.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 6a17969b0..f1ef4198b 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -2100,20 +2100,17 @@ SQL; public static function getMaxLengths() { - global $CC_CONFIG; $con = Propel::getConnection(); - - //Not using prepared statement here since not using an variable input. - $sql = "SELECT column_name, character_maximum_length FROM information_schema.columns" - ." WHERE table_name = 'cc_show' AND character_maximum_length > 0"; + $sql = <<<SQL +SELECT column_name, character_maximum_length FROM information_schema.columns +WHERE table_name = 'cc_show' AND character_maximum_length > 0 +SQL; $result = $con->query($sql)->fetchAll(); - - // store result into assoc array $assocArray = array(); + foreach ($result as $row) { $assocArray[$row['column_name']] = $row['character_maximum_length']; } - return $assocArray; } } From 8f3c7e8ebac179add1df4b441c22f8f109bc2727 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg <rudi.grinberg@sourcefabric.org> Date: Fri, 7 Sep 2012 15:29:30 -0400 Subject: [PATCH 18/24] cc-4347: PDO'd getInstanceOnDate() --- airtime_mvc/application/models/Show.php | 33 ++++++++++++++----------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index f1ef4198b..579c26df5 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -949,20 +949,24 @@ SQL; * row in the cc_show_instances table. */ public function getInstanceOnDate($p_dateTime) { - $con = Propel::getConnection(); - $timestamp = $p_dateTime->format("Y-m-d H:i:s"); - - $showId = $this->getId(); - $sql = "SELECT id FROM cc_show_instances" - ." WHERE date(starts) = date(TIMESTAMP '$timestamp') " - ." AND show_id = $showId AND rebroadcast = 0"; - - $query = $con->query($sql); - $row = ($query !== false) ? $query->fetchColumn(0) : null; - - return CcShowInstancesQuery::create() - ->findPk($row); + $sql = <<<SQL +SELECT id +FROM cc_show_instances +WHERE date(starts) = date(TIMESTAMP :timestamp) + AND show_id = :showId + AND rebroadcast = 0; +SQL; + try { + $row = Application_Common_Database::prepareAndExecute( $sql, + array( 'showId' => $this->getId(), + ':timestamp' => $timestamp ), 'column'); + return CcShowInstancesQuery::create() + ->findPk($row); + } catch (Exception $e) { + return null; + } + } public function deletePossiblyInvalidInstances($p_data, $p_endDate, $isRecorded, $repeatType) @@ -2105,9 +2109,8 @@ SQL; SELECT column_name, character_maximum_length FROM information_schema.columns WHERE table_name = 'cc_show' AND character_maximum_length > 0 SQL; - $result = $con->query($sql)->fetchAll(); + $result = $con->query($sql)->fetchAll(); $assocArray = array(); - foreach ($result as $row) { $assocArray[$row['column_name']] = $row['character_maximum_length']; } From 87787081ce15dffeed6a6eadb7f1b84558415915 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg <rudi.grinberg@sourcefabric.org> Date: Fri, 7 Sep 2012 16:26:05 -0400 Subject: [PATCH 19/24] Removed unused optional argument. --- .../application/controllers/ApiController.php | 2 +- airtime_mvc/application/models/RabbitMq.php | 2 +- airtime_mvc/application/models/Show.php | 47 ++++++++++--------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index cd0ed19d1..1b4613796 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -379,7 +379,7 @@ class ApiController extends Zend_Controller_Action Application_Model_Show::getShows( Application_Common_DateHelper::ConvertToUtcDateTime($today_timestamp, date_default_timezone_get()), Application_Common_DateHelper::ConvertToUtcDateTime($end_timestamp, date_default_timezone_get()), - $excludeInstance = null, $onlyRecord = true); + $onlyRecord = true); $this->view->is_recording = false; $this->view->server_timezone = Application_Model_Preference::GetTimezone(); diff --git a/airtime_mvc/application/models/RabbitMq.php b/airtime_mvc/application/models/RabbitMq.php index cba216f8e..797cdb145 100644 --- a/airtime_mvc/application/models/RabbitMq.php +++ b/airtime_mvc/application/models/RabbitMq.php @@ -88,7 +88,7 @@ class Application_Model_RabbitMq $temp['server_timezone'] = Application_Model_Preference::GetTimezone(); if ($event_type == "update_recorder_schedule") { $temp['shows'] = Application_Model_Show::getShows($now, - $end_timestamp, $excludeInstance=NULL, $onlyRecord=TRUE); + $end_timestamp, $onlyRecord=TRUE); } $data = json_encode($temp); $msg = new AMQPMessage($data, array('content_type' => 'text/plain')); diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 579c26df5..00d65b254 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -1591,7 +1591,7 @@ SQL; * @param boolean $onlyRecord * @return array */ - public static function getShows($start_timestamp, $end_timestamp, $excludeInstance=NULL, $onlyRecord=FALSE) + public static function getShows($start_timestamp, $end_timestamp, $onlyRecord=FALSE) { $con = Propel::getConnection(); @@ -1603,15 +1603,29 @@ SQL; Application_Model_Preference::SetShowsPopulatedUntil($end_timestamp); } - $sql = "SELECT si1.starts AS starts, si1.ends AS ends, si1.record AS record, si1.rebroadcast AS rebroadcast, si2.starts AS parent_starts, - si1.instance_id AS record_id, si1.show_id AS show_id, show.name AS name, - show.color AS color, show.background_color AS background_color, si1.file_id AS file_id, si1.id AS instance_id, - si1.created AS created, si1.last_scheduled AS last_scheduled, si1.time_filled AS time_filled, f.soundcloud_id - FROM cc_show_instances AS si1 - LEFT JOIN cc_show_instances AS si2 ON si1.instance_id = si2.id - LEFT JOIN cc_show AS show ON show.id = si1.show_id - LEFT JOIN cc_files AS f ON f.id = si1.file_id - WHERE si1.modified_instance = FALSE"; + $sql = <<<SQL +SELECT si1.starts AS starts, + si1.ends AS ends, + si1.record AS record, + si1.rebroadcast AS rebroadcast, + si2.starts AS parent_starts, + si1.instance_id AS record_id, + si1.show_id AS show_id, + show.name AS name, + show.color AS color, + show.background_color AS background_color, + si1.file_id AS file_id, + si1.id AS instance_id, + si1.created AS created, + si1.last_scheduled AS last_scheduled, + si1.time_filled AS time_filled, + f.soundcloud_id +FROM cc_show_instances AS si1 +LEFT JOIN cc_show_instances AS si2 ON si1.instance_id = si2.id +LEFT JOIN cc_show AS SHOW ON SHOW.id = si1.show_id +LEFT JOIN cc_files AS f ON f.id = si1.file_id +WHERE si1.modified_instance = FALSE +SQL; //only want shows that are starting at the time or later. $start_string = $start_timestamp->format("Y-m-d H:i:s"); $end_string = $end_timestamp->format("Y-m-d H:i:s"); @@ -1619,25 +1633,14 @@ SQL; $sql = $sql." AND (si1.starts >= '{$start_string}' AND si1.starts < timestamp '{$end_string}')"; $sql = $sql." AND (si1.record = 1)"; + } else { $sql = $sql." AND ((si1.starts >= '{$start_string}' AND si1.starts < '{$end_string}') OR (si1.ends > '{$start_string}' AND si1.ends <= '{$end_string}') OR (si1.starts <= '{$start_string}' AND si1.ends >= '{$end_string}'))"; } - - if (isset($excludeInstance)) { - foreach ($excludeInstance as $instance) { - $sql_exclude[] = "si1.id != {$instance}"; - } - - $exclude = join(" OR ", $sql_exclude); - - $sql = $sql." AND ({$exclude})"; - } - $result = $con->query($sql)->fetchAll(); - return $result; } From 79513356fb270c933c1571ee605b53a849440f4f Mon Sep 17 00:00:00 2001 From: Rudi Grinberg <rudi.grinberg@sourcefabric.org> Date: Fri, 7 Sep 2012 16:53:16 -0400 Subject: [PATCH 20/24] cc-4347: PDO'd getShows --- airtime_mvc/application/models/Show.php | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 00d65b254..d515f20a2 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -1630,18 +1630,27 @@ 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.record = 1)"; - $sql = $sql." AND (si1.starts >= '{$start_string}' AND si1.starts < timestamp '{$end_string}')"; - $sql = $sql." AND (si1.record = 1)"; + return Application_Common_Database::prepareAndExecute( $sql, + array( ':start' => $start_string, + ':end' => $end_string ), 'all'); } else { - - $sql = $sql." AND ((si1.starts >= '{$start_string}' AND si1.starts < '{$end_string}') - OR (si1.ends > '{$start_string}' AND si1.ends <= '{$end_string}') - OR (si1.starts <= '{$start_string}' AND si1.ends >= '{$end_string}'))"; + $sql .= " AND ((si1.starts >= :start1::TIMESTAMPAND si1.starts < :end1::TIMESTAMP) + OR (si1.ends > :start2::TIMESTAMP si1.ends <= :end2::TIMESTAMP) + OR (si1.starts <= :start3::TIMESTAMP AND si1.ends >= :end3::TIMESTAMP))"; + return Application_Common_Database::prepareAndExecute( $sql, + array( + 'start1' => $start_string, + 'start2' => $start_string, + 'start3' => $start_string, + 'end1' => $end_string, + 'end2' => $end_string, + 'end3' => $end_string + ), 'all'); } - $result = $con->query($sql)->fetchAll(); - return $result; } private static function setNextPop($next_date, $show_id, $day) From 7fa17a644ea15a2dc340e395fa862029b3190cee Mon Sep 17 00:00:00 2001 From: Rudi Grinberg <rudi.grinberg@sourcefabric.org> Date: Fri, 7 Sep 2012 16:58:49 -0400 Subject: [PATCH 21/24] Sexification --- airtime_mvc/application/models/Show.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index d515f20a2..278ff9d63 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -1711,10 +1711,10 @@ SQL; */ public static function &getFullCalendarEvents($p_start, $p_end, $p_editable=false) { - $events = array(); + $events = array(); $interval = $p_start->diff($p_end); - $days = $interval->format('%a'); - $shows = Application_Model_Show::getShows($p_start, $p_end); + $days = $interval->format('%a'); + $shows = Application_Model_Show::getShows($p_start, $p_end); $nowEpoch = time(); $timezone = date_default_timezone_get(); From a8e7cb392a3bd5e1e6a44b4e90c1b6aa5d98ae2d Mon Sep 17 00:00:00 2001 From: Rudi Grinberg <rudi.grinberg@sourcefabric.org> Date: Fri, 7 Sep 2012 16:59:35 -0400 Subject: [PATCH 22/24] Sexification 2 --- airtime_mvc/application/controllers/ApiController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 1b4613796..8a968302c 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -371,9 +371,9 @@ class ApiController extends Zend_Controller_Action public function recordedShowsAction() { $today_timestamp = date("Y-m-d H:i:s"); - $now = new DateTime($today_timestamp); - $end_timestamp = $now->add(new DateInterval("PT2H")); - $end_timestamp = $end_timestamp->format("Y-m-d H:i:s"); + $now = new DateTime($today_timestamp); + $end_timestamp = $now->add(new DateInterval("PT2H")); + $end_timestamp = $end_timestamp->format("Y-m-d H:i:s"); $this->view->shows = Application_Model_Show::getShows( From b4748a3b1f49c0bd2384903d0c6d77a8abc14e22 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg <rudi.grinberg@sourcefabric.org> Date: Fri, 7 Sep 2012 17:15:49 -0400 Subject: [PATCH 23/24] cc-4347: Fixed typo --- airtime_mvc/application/models/Show.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 278ff9d63..9faab43e2 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -1620,10 +1620,10 @@ SELECT si1.starts AS starts, si1.last_scheduled AS last_scheduled, si1.time_filled AS time_filled, f.soundcloud_id -FROM cc_show_instances AS si1 -LEFT JOIN cc_show_instances AS si2 ON si1.instance_id = si2.id -LEFT JOIN cc_show AS SHOW ON SHOW.id = si1.show_id -LEFT JOIN cc_files AS f ON f.id = si1.file_id +FROM cc_show_instances AS si1 +LEFT JOIN cc_show_instances AS si2 ON si1.instance_id = si2.id +LEFT JOIN cc_show AS show ON show.id = si1.show_id +LEFT JOIN cc_files AS f ON f.id = si1.file_id WHERE si1.modified_instance = FALSE SQL; //only want shows that are starting at the time or later. @@ -1638,7 +1638,7 @@ SQL; ':end' => $end_string ), 'all'); } else { - $sql .= " AND ((si1.starts >= :start1::TIMESTAMPAND si1.starts < :end1::TIMESTAMP) + $sql .= " AND ((si1.starts >= :start1::TIMESTAMP AND si1.starts < :end1::TIMESTAMP) OR (si1.ends > :start2::TIMESTAMP si1.ends <= :end2::TIMESTAMP) OR (si1.starts <= :start3::TIMESTAMP AND si1.ends >= :end3::TIMESTAMP))"; return Application_Common_Database::prepareAndExecute( $sql, From f1487ba69da86257645716e1578443d185891c6b Mon Sep 17 00:00:00 2001 From: Rudi Grinberg <rudi.grinberg@sourcefabric.org> Date: Fri, 7 Sep 2012 17:23:32 -0400 Subject: [PATCH 24/24] cc-4347: Fixed missing AND clause --- airtime_mvc/application/models/Show.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 9faab43e2..a41345065 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -1638,9 +1638,11 @@ SQL; ':end' => $end_string ), 'all'); } else { - $sql .= " AND ((si1.starts >= :start1::TIMESTAMP AND si1.starts < :end1::TIMESTAMP) - OR (si1.ends > :start2::TIMESTAMP si1.ends <= :end2::TIMESTAMP) - OR (si1.starts <= :start3::TIMESTAMP AND si1.ends >= :end3::TIMESTAMP))"; + $sql .= " ". <<<SQL +AND ((si1.starts >= :start1::TIMESTAMP AND si1.starts < :end1::TIMESTAMP) + OR (si1.ends > :start2::TIMESTAMP AND si1.ends <= :end2::TIMESTAMP) + OR (si1.starts <= :start3::TIMESTAMP AND si1.ends >= :end3::TIMESTAMP)) +SQL; return Application_Common_Database::prepareAndExecute( $sql, array( 'start1' => $start_string,