From 0fdf1e5e86bfea8ef7af95ae9c696dc785862666 Mon Sep 17 00:00:00 2001
From: Rudi Grinberg <rudi.grinberg@sourcefabric.org>
Date: Thu, 6 Sep 2012 15:47:07 -0400
Subject: [PATCH 1/3] cc-4347: PDO

---
 airtime_mvc/application/models/Show.php | 42 ++++++++++++++++++++-----
 1 file changed, 35 insertions(+), 7 deletions(-)

diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php
index 821179e21..25863e1c4 100644
--- a/airtime_mvc/application/models/Show.php
+++ b/airtime_mvc/application/models/Show.php
@@ -220,18 +220,46 @@ class Application_Model_Show
         $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');";
+        $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 = $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)
+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)
+WHERE show_id = :show_id2
+AND ((CAST(duration AS interval) + interval :deltaDay4 + interval :interval4) <= interval '24:00')
+SQL;
+
+        Application_Common_Database::prepareAndExecute($sql_gen,
+            array(
+                ':deltaDay1'          => "$deltaDay days",
+                ':interval1'          => "$hours:$mins",
+                ':show_id1'           =>  $this->_showId,
+                ':current_timestamp1' =>  $current_timestamp,
+                ':deltaDay2'          => "$deltaDay days",
+                ':interval2'          => "$hours:$mins",
+                ':deltaDay3'          => "$deltaDay days",
+                ':interval3'          => "$hours:$mins",
+                ':show_id2'           =>  $this->_showId,
+                ':deltaDay4'          => "$deltaDay days",
+                ':interval4'          => "$hours:$mins"
+            ), "execute");
 
         //do both the queries at once.
-        $con->exec($sql);
+        //$con->exec($sql);
 
         $con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME);
         $con->beginTransaction();

From 977c664bfeb62038d1c268d354ff16b935be8345 Mon Sep 17 00:00:00 2001
From: Rudi Grinberg <rudi.grinberg@sourcefabric.org>
Date: Thu, 6 Sep 2012 15:49:13 -0400
Subject: [PATCH 2/3] cc-4347: Fixed table quoting

---
 airtime_mvc/application/models/Schedule.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/airtime_mvc/application/models/Schedule.php b/airtime_mvc/application/models/Schedule.php
index 4c3706f5b..6abdaa94a 100644
--- a/airtime_mvc/application/models/Schedule.php
+++ b/airtime_mvc/application/models/Schedule.php
@@ -1078,7 +1078,6 @@ SQL;
                     and modified_instance = false and id != :instanceId order by ends");
             
             $stmt->execute(array(
-                ':showInstances' => $CC_CONFIG['showInstances'],
                 ':show_end1'     => $show_end->format('Y-m-d H:i:s'),
                 ':show_end2'     => $show_end->format('Y-m-d H:i:s'),
                 ':show_end3'     => $show_end->format('Y-m-d H:i:s'),

From 1852843f96ccb0c01ad04529da89ed914427c119 Mon Sep 17 00:00:00 2001
From: Rudi Grinberg <rudi.grinberg@sourcefabric.org>
Date: Thu, 6 Sep 2012 15:55:29 -0400
Subject: [PATCH 3/3] cc-4347: ~~~~PDO~~~~~~

---
 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 25863e1c4..8018e4f6c 100644
--- a/airtime_mvc/application/models/Show.php
+++ b/airtime_mvc/application/models/Show.php
@@ -796,11 +796,11 @@ SQL;
         $timestamp = $date->getUtcTimestamp();
 
         $stmt =  $con->prepare("UPDATE cc_show_days "
-                 ."SET duration = :add_show_duration"
+                 ."SET duration = :add_show_duration "
                  ."WHERE show_id = :add_show_id" );
         $stmt->execute( array(
-            ':add_show_duration' => $p_data[add_show_duration],
-            ':add_show_id' => $p_data[add_show_id]
+            ':add_show_duration' => $p_data['add_show_duration'],
+            ':add_show_id' => $p_data['add_show_id']
         ));
 
         $sql = "UPDATE cc_show_instances "