From 36a68aa589971142a3ccacdb8e3d803ac950fb3a Mon Sep 17 00:00:00 2001
From: martin <martin@martin-ThinkPad-T410.(none)>
Date: Wed, 23 Mar 2011 16:37:35 -0400
Subject: [PATCH 1/5] -incorrectly removing directories in pypo-uninstall
 script fixed

---
 pypo/install/pypo-uninstall.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pypo/install/pypo-uninstall.py b/pypo/install/pypo-uninstall.py
index a9f339be0..6dcc42ce5 100644
--- a/pypo/install/pypo-uninstall.py
+++ b/pypo/install/pypo-uninstall.py
@@ -38,16 +38,16 @@ try:
     remove_path(BASE_PATH)
     
     print "Removing daemontool script pypo"
-    remove_path("rm -rf /etc/service/pypo")
+    remove_path("/etc/service/pypo")
 
     if os.path.exists("/etc/service/pypo-fetch"):
-        remove_path("rm -rf /etc/service/pypo-fetch")
+        remove_path("/etc/service/pypo-fetch")
 
     if os.path.exists("/etc/service/pypo-push"):
-        remove_path("rm -rf /etc/service/pypo-push")
+        remove_path("/etc/service/pypo-push")
         
     print "Removing daemontool script pypo-liquidsoap"
-    remove_path("rm -rf /etc/service/pypo-liquidsoap")
+    remove_path("/etc/service/pypo-liquidsoap")
 
     remove_user("pypo")
     print "Uninstall complete."

From 8a2610aa8482acb04e9b331aafd8e2230c623991 Mon Sep 17 00:00:00 2001
From: martin <martin@martin-ThinkPad-T410.(none)>
Date: Wed, 23 Mar 2011 22:14:57 -0400
Subject: [PATCH 2/5] CC-1894: Warn users about time zone differences or clock
 drift problems on the server -Now using timezone offsets from UTC instead of
 regions to compare timezones between pypo and the airtime webserver

---
 application/models/Schedule.php |  2 +-
 pypo/pypofetch.py               | 14 ++++++++------
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/application/models/Schedule.php b/application/models/Schedule.php
index aaff58ef9..ba5b97290 100644
--- a/application/models/Schedule.php
+++ b/application/models/Schedule.php
@@ -716,7 +716,7 @@ class Schedule {
         $result['stream_metadata'] = array();
         $result['stream_metadata']['format'] = Application_Model_Preference::GetStreamLabelFormat();
         $result['stream_metadata']['station_name'] = Application_Model_Preference::GetStationName();
-        $result['server_timezone'] = date_default_timezone_get();
+        $result['server_timezone'] = date('O');
 
         return $result;
     }
diff --git a/pypo/pypofetch.py b/pypo/pypofetch.py
index 0313e9567..2958c6bd4 100644
--- a/pypo/pypofetch.py
+++ b/pypo/pypofetch.py
@@ -11,6 +11,7 @@ import json
 import telnetlib
 import math
 from threading import Thread
+from subprocess import Popen, PIPE
 
 # For RabbitMQ
 from kombu.connection import BrokerConnection
@@ -78,13 +79,14 @@ class PypoFetch(Thread):
 
     def check_matching_timezones(self, server_timezone):
         logger = logging.getLogger('fetch')
-        f = open('/etc/timezone', 'r')
-        pypo_timezone = f.readline().strip(' \t\n\r')
-        f.close()
+
+        process = Popen(["date", "+%z"], stdout=PIPE)
+        pypo_timezone = (process.communicate()[0]).strip(' \r\n\t')
+
         if server_timezone != pypo_timezone:
-            logger.error("Server and pypo timezones do not match. Audio playback may not start when expected!")
-            logger.error("Server timezone: %s", server_timezone)
-            logger.error("Pypo timezone: %s", pypo_timezone)
+            logger.error("Server and pypo timezone offsets do not match. Audio playback may not start when expected!")
+            logger.error("Server timezone offset: %s", server_timezone)
+            logger.error("Pypo timezone offset: %s", pypo_timezone)
     
     """
     Process the schedule

From 3fed7a7ab59b8548bf0331bd0df46fddd0e1fb71 Mon Sep 17 00:00:00 2001
From: martin <martin@martin-ThinkPad-T410.(none)>
Date: Wed, 23 Mar 2011 22:22:07 -0400
Subject: [PATCH 3/5] CC-2045: Role drop-down box has no label in Manage users
 page, should default to 'guest' -fixed

---
 application/forms/AddUser.php | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/application/forms/AddUser.php b/application/forms/AddUser.php
index e1f0453a7..d1eca586b 100644
--- a/application/forms/AddUser.php
+++ b/application/forms/AddUser.php
@@ -68,12 +68,13 @@ class Application_Form_AddUser extends Zend_Form
         $this->addElement($jabber);
 
         $select = new Zend_Form_Element_Select('type');
+        $select->setLabel('User Type:');
         $select->setAttrib('class', 'input_select');
         $select->setAttrib('style', 'width: 40%');
         $select->setMultiOptions(array(
-                "A" => "admin",
-                "H" => "host",
                 "G" => "guest",
+                "H" => "host",
+                "A" => "admin"
             ));
         $select->setRequired(true);
         $this->addElement($select);

From 50432c0b66093dea663ba8af397fbd59e2626ab2 Mon Sep 17 00:00:00 2001
From: martin <martin@martin-ThinkPad-T410.(none)>
Date: Wed, 23 Mar 2011 22:32:12 -0400
Subject: [PATCH 4/5] CC-2046: About box could display version number -Done

---
 application/views/scripts/partialviews/header.phtml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/application/views/scripts/partialviews/header.phtml b/application/views/scripts/partialviews/header.phtml
index 4905d0d10..a817fc1fd 100644
--- a/application/views/scripts/partialviews/header.phtml
+++ b/application/views/scripts/partialviews/header.phtml
@@ -43,6 +43,6 @@
 <div id="jquery_jplayer_1" class="jp-jplayer" style="width:0px; height:0px;"></div>
 
 <div id="about-txt" style="display: none;">
-<a href="http://airtime.sourcefabric.org">Airtime</a>, the open radio software for scheduling and remote station management.<br>
+<a href="http://airtime.sourcefabric.org">Airtime</a> 1.7, the open radio software for scheduling and remote station management.<br>
 © 2011 <a href="http://www.sourcefabric.org">Sourcefabric</a> o.p.s 2011. Airtime is distributed under the <a href="http://www.gnu.org/licenses/gpl-3.0-standalone.html">GNU GPL v.3</a>
 </div>

From f9c8a7cc11e904adc6af9d74a600eff667e4c15b Mon Sep 17 00:00:00 2001
From: "paul.baranowski" <paul.baranowski@sourcefabric.org>
Date: Wed, 23 Mar 2011 23:24:06 -0400
Subject: [PATCH 5/5] CC-2096 	Schedule changes should be sent to RabbitMQ at
 most once per user request

Implemented as a plugin to Zend.  Now at most one schedule push to RabbitMQ
will happen per user action.  It's pretty sweet.
---
 application/Bootstrap.php                     | 22 ++++++-----
 .../controllers/plugins/RabbitMqPlugin.php    |  9 +++++
 application/models/RabbitMq.php               | 39 ++++++++++++-------
 3 files changed, 47 insertions(+), 23 deletions(-)
 create mode 100644 application/controllers/plugins/RabbitMqPlugin.php

diff --git a/application/Bootstrap.php b/application/Bootstrap.php
index bf9591e56..19a2cc72c 100644
--- a/application/Bootstrap.php
+++ b/application/Bootstrap.php
@@ -1,7 +1,7 @@
 <?php
 
-require_once (__DIR__."/configs/navigation.php");
-require_once (__DIR__."/configs/ACL.php");
+require_once __DIR__."/configs/navigation.php";
+require_once __DIR__."/configs/ACL.php";
 
 require_once 'propel/runtime/lib/Propel.php';
 Propel::init(__DIR__."/configs/airtime-conf.php");
@@ -10,8 +10,8 @@ Propel::init(__DIR__."/configs/airtime-conf.php");
 $tz = ini_get('date.timezone') ? ini_get('date.timezone') : 'UTC';
 date_default_timezone_set($tz);
 
-require_once (__DIR__."/configs/constants.php");
-require_once (__DIR__."/configs/conf.php");
+require_once __DIR__."/configs/constants.php";
+require_once __DIR__."/configs/conf.php";
 require_once 'DB.php';
 
 require_once 'Soundcloud.php';
@@ -21,7 +21,7 @@ require_once 'Schedule.php';
 require_once 'Shows.php';
 require_once 'Users.php';
 require_once 'RabbitMq.php';
-
+require_once __DIR__.'/controllers/plugins/RabbitMqPlugin.php';
 
 global $CC_CONFIG, $CC_DBC;
 $dsn = $CC_CONFIG['dsn'];
@@ -36,6 +36,9 @@ $CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
 //Zend_Session::start();
 Zend_Validate::setDefaultNamespaces("Zend");
 
+$front = Zend_Controller_Front::getInstance();
+$front->registerPlugin(new RabbitMqPlugin());
+
 class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
 {
 	protected function _initDoctype()
@@ -48,9 +51,7 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
 	protected function _initHeadLink()
 	{
 		$view = $this->getResource('view');
-
 		$view->headLink()->appendStylesheet('/css/redmond/jquery-ui-1.8.8.custom.css');
-
         $this->view->headLink()->appendStylesheet('/css/pro_dropdown_3.css');
 		$this->view->headLink()->appendStylesheet('/css/styles.css');
 	}
@@ -70,14 +71,17 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
         $view->headScript()->appendFile('/js/airtime/common/common.js','text/javascript');
     }
 
-    protected function _initViewHelpers(){
+    protected function _initViewHelpers()
+    {
         $view = $this->getResource('view');
         $view->addHelperPath('../application/views/helpers', 'Airtime_View_Helper');
     }
 
-    protected function _initTitle(){
+    protected function _initTitle()
+    {
         $view = $this->getResource('view');
         $view->headTitle(Application_Model_Preference::GetHeadTitle());
     }
+
 }
 
diff --git a/application/controllers/plugins/RabbitMqPlugin.php b/application/controllers/plugins/RabbitMqPlugin.php
new file mode 100644
index 000000000..3316f01b2
--- /dev/null
+++ b/application/controllers/plugins/RabbitMqPlugin.php
@@ -0,0 +1,9 @@
+<?php
+
+class RabbitMqPlugin extends Zend_Controller_Plugin_Abstract
+{
+    public function dispatchLoopShutdown()
+    {
+        RabbitMq::PushScheduleFinal();
+    }
+}
\ No newline at end of file
diff --git a/application/models/RabbitMq.php b/application/models/RabbitMq.php
index af5bffa02..e2749149c 100644
--- a/application/models/RabbitMq.php
+++ b/application/models/RabbitMq.php
@@ -3,30 +3,41 @@ require_once 'php-amqplib/amqp.inc';
 
 class RabbitMq
 {
+    static private $doPush = FALSE;
+
+    /**
+     * Sets a flag to push the schedule at the end of the request.
+     */
+    public static function PushSchedule() {
+        RabbitMq::$doPush = TRUE;
+    }
 
     /**
      * Push the current schedule to RabbitMQ, to be picked up by Pypo.
      * Will push the schedule in the range from 24 hours ago to 24 hours
      * in the future.
      */
-    public static function PushSchedule() {
+    public static function PushScheduleFinal()
+    {
         global $CC_CONFIG;
-        $conn = new AMQPConnection($CC_CONFIG["rabbitmq"]["host"],
-                                         $CC_CONFIG["rabbitmq"]["port"],
-                                         $CC_CONFIG["rabbitmq"]["user"],
-                                         $CC_CONFIG["rabbitmq"]["password"]);
-        $channel = $conn->channel();
-        $channel->access_request($CC_CONFIG["rabbitmq"]["vhost"], false, false, true, true);
+        if (RabbitMq::$doPush) {
+            $conn = new AMQPConnection($CC_CONFIG["rabbitmq"]["host"],
+                                             $CC_CONFIG["rabbitmq"]["port"],
+                                             $CC_CONFIG["rabbitmq"]["user"],
+                                             $CC_CONFIG["rabbitmq"]["password"]);
+            $channel = $conn->channel();
+            $channel->access_request($CC_CONFIG["rabbitmq"]["vhost"], false, false, true, true);
 
-        $EXCHANGE = 'airtime-schedule';
-        $channel->exchange_declare($EXCHANGE, 'direct', false, true);
+            $EXCHANGE = 'airtime-schedule';
+            $channel->exchange_declare($EXCHANGE, 'direct', false, true);
 
-        $data = json_encode(Schedule::ExportRangeAsJson());
-        $msg = new AMQPMessage($data, array('content_type' => 'text/plain'));
+            $data = json_encode(Schedule::ExportRangeAsJson());
+            $msg = new AMQPMessage($data, array('content_type' => 'text/plain'));
 
-        $channel->basic_publish($msg, $EXCHANGE);
-        $channel->close();
-        $conn->close();
+            $channel->basic_publish($msg, $EXCHANGE);
+            $channel->close();
+            $conn->close();
+        }
     }
 
 }