From ca012afde7cb061417f3685a22acce4a6dc230dd Mon Sep 17 00:00:00 2001
From: Martin Konecny <martin.konecny@gmail.com>
Date: Thu, 6 Sep 2012 14:50:52 -0400
Subject: [PATCH 1/7] CC-4341: Report of stream status does not work the first
 time, but works after 'Save' is clicked

-added missing package to install script
---
 install_full/ubuntu/airtime-full-install       | 3 ++-
 install_full/ubuntu/airtime-full-install-nginx | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/install_full/ubuntu/airtime-full-install b/install_full/ubuntu/airtime-full-install
index 49755239a..d70429d6d 100755
--- a/install_full/ubuntu/airtime-full-install
+++ b/install_full/ubuntu/airtime-full-install
@@ -51,7 +51,8 @@ php-pear php5-gd postgresql odbc-postgresql python libsoundtouch-ocaml \
 libtaglib-ocaml libao-ocaml libmad-ocaml ecasound \
 libesd0 libportaudio2 libsamplerate0 rabbitmq-server patch \
 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
 #of Debian, where these packages are unauthorized)
diff --git a/install_full/ubuntu/airtime-full-install-nginx b/install_full/ubuntu/airtime-full-install-nginx
index 407b52eb6..0f6abf950 100755
--- a/install_full/ubuntu/airtime-full-install-nginx
+++ b/install_full/ubuntu/airtime-full-install-nginx
@@ -42,7 +42,8 @@ php-pear php5-gd postgresql odbc-postgresql python libsoundtouch-ocaml \
 libtaglib-ocaml libao-ocaml libmad-ocaml ecasound \
 libesd0 libportaudio2 libsamplerate0 rabbitmq-server patch \
 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
 #of Debian, where these packages are unauthorized)

From 18ec23526fa09f5587b087e7e624415cb5a91038 Mon Sep 17 00:00:00 2001
From: Martin Konecny <martin.konecny@gmail.com>
Date: Thu, 6 Sep 2012 15:02:26 -0400
Subject: [PATCH 2/7] CC-4294: Webstream length should make hours or minutes
 optional. Also minutes > 59 should be parsed correctly.

-fixed
---
 airtime_mvc/application/models/Webstream.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/airtime_mvc/application/models/Webstream.php b/airtime_mvc/application/models/Webstream.php
index 8c74dca5a..22d51a3e8 100644
--- a/airtime_mvc/application/models/Webstream.php
+++ b/airtime_mvc/application/models/Webstream.php
@@ -115,7 +115,7 @@ class Application_Model_Webstream implements Application_Model_LibraryEditable
 
         $di = null;
         $length = $parameters["length"];
-        $result = preg_match("/^(?:([0-9]{1,2})h)?\s*(?:([0-6]?[0-9])m)?$/", $length, $matches);
+        $result = preg_match("/^(?:([0-9]{1,2})h)?\s*(?:([0-9]{1,2})m)?$/", $length, $matches);
 
         $invalid_date_interval = false;
         if ($result == 1 && count($matches) == 2) {

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 3/7] 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 4/7] 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 5/7] 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 "

From fba5d56c7641b8f691e487ce7e4961d5718d602c Mon Sep 17 00:00:00 2001
From: Martin Konecny <martin.konecny@gmail.com>
Date: Thu, 6 Sep 2012 16:18:28 -0400
Subject: [PATCH 6/7] CC-4364: Show - > On Air button is greyed out although
 you can hear the playout

-fixed
---
 airtime_mvc/application/models/Schedule.php | 4 ++--
 airtime_mvc/application/models/Show.php     | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/airtime_mvc/application/models/Schedule.php b/airtime_mvc/application/models/Schedule.php
index 4c3706f5b..e6f8c8705 100644
--- a/airtime_mvc/application/models/Schedule.php
+++ b/airtime_mvc/application/models/Schedule.php
@@ -52,7 +52,8 @@ class Application_Model_Schedule
             "currentShow"=>$shows['currentShow'],
             "nextShow"=>$shows['nextShow'],
             "timezone"=> date("T"),
-            "timezoneOffset"=> date("Z"));
+            "timezoneOffset"=> date("Z")
+        );
 
         return $range;
     }
@@ -71,7 +72,6 @@ class Application_Model_Schedule
             return;
         }
 
-        global $CC_CONFIG;
         $con = Propel::getConnection();
         $sql = "SELECT %%columns%% st.starts as starts, st.ends as ends,
             st.media_item_played as media_item_played, si.ends as show_ends
diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php
index 821179e21..02158a0ca 100644
--- a/airtime_mvc/application/models/Show.php
+++ b/airtime_mvc/application/models/Show.php
@@ -1838,7 +1838,7 @@ SELECT si.starts AS start_timestamp,
        ends
 FROM cc_show_instances si
      LEFT JOIN cc_show s
-     ON si.instance_id = s.id
+     ON si.show_id = s.id
 WHERE si.show_id = s.id
   AND si.starts <= :timeNow1::timestamp
   AND si.ends > :timeNow2::timestamp
@@ -1881,7 +1881,7 @@ SELECT si.starts AS start_timestamp,
        ends
 FROM cc_show_instances si
      LEFT JOIN cc_show s
-     ON si.instance_id = s.id
+     ON si.show_id = s.id
 WHERE si.show_id = s.id
   AND si.starts > :timeNow1::timestamp - INTERVAL '2 days'
   AND si.ends < :timeNow2::timestamp + INTERVAL '2 days'
@@ -1895,7 +1895,7 @@ SQL;
         $stmt->bindValue(':timeNow2', $p_timeNow);
 
         if ($stmt->execute()) {
-            $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
+            $rows = $stmt->fetchAll();
         } else {
             $msg = implode(',', $stmt->errorInfo());
             throw new Exception("Error: $msg");
@@ -2020,7 +2020,7 @@ SELECT si.starts AS start_timestamp,
        ends
 FROM cc_show_instances si
      LEFT JOIN cc_show s
-     ON si.instance_id = s.id
+     ON si.show_id = s.id
 WHERE si.show_id = s.id
   AND si.starts >= :timeStart::timestamp
   AND si.starts < :timeEnd::timestamp

From 18f310d28bcb5a8ef089579b0cf2b66c8ec9c929 Mon Sep 17 00:00:00 2001
From: Martin Konecny <martin.konecny@gmail.com>
Date: Thu, 6 Sep 2012 16:36:39 -0400
Subject: [PATCH 7/7] CC-4365: Installation - Full installation is complaining
 on "Package timeout is not available"

-fixed
---
 install_full/ubuntu/airtime-full-install       | 11 +++++++++--
 install_full/ubuntu/airtime-full-install-nginx | 14 ++++++++++----
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/install_full/ubuntu/airtime-full-install b/install_full/ubuntu/airtime-full-install
index d70429d6d..af135b124 100755
--- a/install_full/ubuntu/airtime-full-install
+++ b/install_full/ubuntu/airtime-full-install
@@ -23,6 +23,7 @@ echo " 1. Install Packages"
 echo "----------------------------------------------------"
 
 dist=`lsb_release -is`
+code=`lsb_release -cs`
 
 if [ "$dist" = "Debian" ]; then
     set +e
@@ -51,8 +52,7 @@ php-pear php5-gd postgresql odbc-postgresql python libsoundtouch-ocaml \
 libtaglib-ocaml libao-ocaml libmad-ocaml ecasound \
 libesd0 libportaudio2 libsamplerate0 rabbitmq-server patch \
 php5-curl mpg123 monit python-virtualenv multitail libcamomile-ocaml-data \
-libpulse0 vorbis-tools lsb-release lsof sudo mp3gain vorbisgain flac vorbis-tools \
-timeout
+libpulse0 vorbis-tools lsb-release lsof sudo mp3gain vorbisgain flac vorbis-tools
 
 #install packages with --force-yes option (this is useful in the case
 #of Debian, where these packages are unauthorized)
@@ -68,6 +68,13 @@ else
     apt-get -y install libzend-framework-php
 fi
 
+if [ "$code" = "lucid" ]; then
+    apt-get -y install timeout 
+else
+    apt-get -y install coreutils
+fi
+
+
 #Install Sourcefabric's custom Liquidsoap debian package
 apt-get -y --force-yes install sourcefabric-keyring
 apt-get -y --force-yes install liquidsoap
diff --git a/install_full/ubuntu/airtime-full-install-nginx b/install_full/ubuntu/airtime-full-install-nginx
index 0f6abf950..c89e81198 100755
--- a/install_full/ubuntu/airtime-full-install-nginx
+++ b/install_full/ubuntu/airtime-full-install-nginx
@@ -26,11 +26,12 @@ echo " 1. Install Packages"
 echo "----------------------------------------------------"
 
 dist=`lsb_release -is`
+code=`lsb_release -cs`
 
 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
-        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
 
@@ -42,8 +43,7 @@ php-pear php5-gd postgresql odbc-postgresql python libsoundtouch-ocaml \
 libtaglib-ocaml libao-ocaml libmad-ocaml ecasound \
 libesd0 libportaudio2 libsamplerate0 rabbitmq-server patch \
 php5-curl mpg123 monit python-virtualenv multitail libcamomile-ocaml-data \
-libpulse0 vorbis-tools lsb-release lsof sudo mp3gain vorbisgain flac vorbis-tools \
-timeout
+libpulse0 vorbis-tools lsb-release lsof sudo mp3gain vorbisgain flac vorbis-tools 
 
 #install packages with --force-yes option (this is useful in the case
 #of Debian, where these packages are unauthorized)
@@ -58,6 +58,12 @@ else
     apt-get -y install libzend-framework-php
 fi
 
+if [ "$code" = "lucid" ]; then
+    apt-get -y install timeout 
+else
+    apt-get -y install coreutils
+fi
+
 # NGINX Config File
 echo "----------------------------------------------------"
 echo "2.1 NGINX Config File"