From 8f335230950fa6ba531bb7535bff64a5c7a6d524 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Wed, 5 Sep 2012 17:35:08 -0400 Subject: [PATCH 1/5] cc-4347: PDO --- airtime_mvc/application/models/Schedule.php | 2 +- airtime_mvc/application/models/ShowInstance.php | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/airtime_mvc/application/models/Schedule.php b/airtime_mvc/application/models/Schedule.php index 63e594bb8..74a45da2d 100644 --- a/airtime_mvc/application/models/Schedule.php +++ b/airtime_mvc/application/models/Schedule.php @@ -1102,7 +1102,7 @@ SQL; )); } //$rows = $con->query($sql); - $rows->fetchAll(); + $rows = $stmt->fetchAll(); foreach ($rows as $row) { $start = new DateTime($row["starts"], new DateTimeZone('UTC')); diff --git a/airtime_mvc/application/models/ShowInstance.php b/airtime_mvc/application/models/ShowInstance.php index b90051c7f..d002ad5aa 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -663,7 +663,7 @@ FROM ( f.filepath AS filepath FROM cc_schedule AS s LEFT JOIN cc_files AS f ON f.id = s.file_id - WHERE s.instance_id = '{$this->_instanceId}' + WHERE s.instance_id = :instance_id1 AND s.playout_status >= 0 AND s.file_id IS NOT NULL) UNION @@ -680,13 +680,18 @@ FROM ( FROM cc_schedule AS s LEFT JOIN cc_webstream AS ws ON ws.id = s.stream_id LEFT JOIN cc_subjs AS sub ON ws.creator_id = sub.id - WHERE s.instance_id = '{$this->_instanceId}' + WHERE s.instance_id = :instance_id2 AND s.playout_status >= 0 AND s.stream_id IS NOT NULL)) AS temp ORDER BY starts; SQL; - $results = $con->query($sql)->fetchAll(PDO::FETCH_ASSOC); + $stmt = $con->prepare($sql); + $stmt->execute(array( + ':instance_id1' => $this->_instanceId, + ':instance_id2' => $this->_instanceId + )); + $results = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($results as &$row) { From 0385c008ce82df9f5f2c093f8cc49d924bf14c02 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Wed, 5 Sep 2012 17:46:29 -0400 Subject: [PATCH 2/5] cc-4347: PDO00!!! --- .../application/models/ShowInstance.php | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/airtime_mvc/application/models/ShowInstance.php b/airtime_mvc/application/models/ShowInstance.php index d002ad5aa..a20e59689 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -324,24 +324,28 @@ class Application_Model_ShowInstance { $con = Propel::getConnection(); - $hours = $deltaMin/60; - if($hours > 0) - $hours = floor($hours); - else - $hours = ceil($hours); + $hours = $deltaMin / 60; - $mins = abs($deltaMin%60); + $hours = ($hours > 0) ? floor($hours) : ceil($hours); + + $mins = abs($deltaMin % 60); $today_timestamp = gmdate("Y-m-d H:i:s"); - $starts = $this->getShowInstanceStart(); - $ends = $this->getShowInstanceEnd(); + $starts = $this->getShowInstanceStart(); + $ends = $this->getShowInstanceEnd(); if (strtotime($today_timestamp) > strtotime($starts)) { return "can't resize a past show"; } - $sql = "SELECT timestamp '{$ends}' + interval '{$deltaDay} days' + interval '{$hours}:{$mins}'"; - $new_ends = $con->query($sql)->fetchColumn(0); + //$sql = "SELECT timestamp '{$ends}' + interval '{$deltaDay} days' + interval '{$hours}:{$mins}'"; + $sql = "SELECT timestamp :ends + interval :deltaDays + interval :deltaTime"; + + $now_ends = Application_Common_Database::prepareAndExecute($sql, + array(':ends' => $ends, + ':deltaDays' => "$deltaDay days", + ':deltaTime' => "{$hours}:{$mins}"), 'column' + ); //only need to check overlap if show increased in size. if (strtotime($new_ends) > strtotime($ends)) { From d2e883da7a805bdf2b99e43267b61bd068db6550 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Wed, 5 Sep 2012 17:48:15 -0400 Subject: [PATCH 3/5] Added type annotation --- airtime_mvc/application/common/Database.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/airtime_mvc/application/common/Database.php b/airtime_mvc/application/common/Database.php index 9977278c0..10ca59b09 100644 --- a/airtime_mvc/application/common/Database.php +++ b/airtime_mvc/application/common/Database.php @@ -1,6 +1,6 @@ prepare($sql); foreach ($paramValueMap as $param => $v) { @@ -21,4 +21,4 @@ class Application_Common_Database{ } return $rows; } -} \ No newline at end of file +} From 73e152ebcfc90b2c5fb5ad667bcf0ff72ddf3eb5 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Wed, 5 Sep 2012 17:51:50 -0400 Subject: [PATCH 4/5] added type annotation again --- airtime_mvc/application/common/Database.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airtime_mvc/application/common/Database.php b/airtime_mvc/application/common/Database.php index ca118a6aa..0eb08f02d 100644 --- a/airtime_mvc/application/common/Database.php +++ b/airtime_mvc/application/common/Database.php @@ -1,7 +1,7 @@ prepare($sql); From 8be51d5bf47ff9b505261ab05dd7f3f74561ad69 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Wed, 5 Sep 2012 17:52:27 -0400 Subject: [PATCH 5/5] sexified code --- 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 a20e59689..8cddfbee2 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -385,7 +385,7 @@ class Application_Model_ShowInstance $scheduler = new Application_Model_Scheduler(); $scheduler->scheduleAfter( - array(array("id" => 0, "instance" => $id, "timestamp" => $ts)), + array(array("id" => 0, "instance" => $id, "timestamp" => $ts)), array(array("id" => $pl_id, "type" => "playlist")) ); }