diff --git a/airtime_mvc/application/Bootstrap.php b/airtime_mvc/application/Bootstrap.php index 0a7824bd8..f8d0886aa 100644 --- a/airtime_mvc/application/Bootstrap.php +++ b/airtime_mvc/application/Bootstrap.php @@ -16,12 +16,36 @@ require_once 'MusicDir.php'; require_once 'Playlist.php'; require_once 'StoredFile.php'; require_once 'Schedule.php'; +require_once 'Preference.php'; require_once 'Shows.php'; require_once 'Users.php'; require_once 'RabbitMq.php'; require_once 'DateHelper.php'; require_once __DIR__.'/controllers/plugins/RabbitMqPlugin.php'; +global $CC_CONFIG, $CC_DBC; +$dsn = $CC_CONFIG['dsn']; + +$CC_DBC = DB::connect($dsn, FALSE); +if (PEAR::isError($CC_DBC)) { + echo "ERROR: ".$CC_DBC->getMessage()." ".$CC_DBC->getUserInfo()."\n"; + exit(1); +} +$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC); + +//DateTime in PHP 5.3.0+ need a default timezone set. +date_default_timezone_set(Application_Model_Preference::GetTimezone()); + +Logging::setLogPath('/var/log/airtime/zendphp.log'); + +Zend_Validate::setDefaultNamespaces("Zend"); + +$front = Zend_Controller_Front::getInstance(); +$front->registerPlugin(new RabbitMqPlugin()); + + +/* The bootstrap class should only be used to initialize actions that return a view. + Actions that return JSON will not use the bootstrap class! */ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { protected function _initDoctype() @@ -69,29 +93,5 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap $view = $this->getResource('view'); $view->headTitle(Application_Model_Preference::GetHeadTitle()); } - - protected function _initDbConnection(){ - global $CC_CONFIG, $CC_DBC; - $dsn = $CC_CONFIG['dsn']; - - $CC_DBC = DB::connect($dsn, FALSE); - if (PEAR::isError($CC_DBC)) { - echo "ERROR: ".$CC_DBC->getMessage()." ".$CC_DBC->getUserInfo()."\n"; - exit(1); - } - $CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC); - - //DateTime in PHP 5.3.0+ need a default timezone set. - date_default_timezone_set(Application_Model_Preference::GetTimezone()); - } - - protected function _initMisc(){ - Logging::setLogPath('/var/log/airtime/zendphp.log'); - - Zend_Validate::setDefaultNamespaces("Zend"); - - $front = Zend_Controller_Front::getInstance(); - $front->registerPlugin(new RabbitMqPlugin()); - } } diff --git a/airtime_mvc/application/controllers/plugins/RabbitMqPlugin.php b/airtime_mvc/application/controllers/plugins/RabbitMqPlugin.php index 3316f01b2..1a55522ae 100644 --- a/airtime_mvc/application/controllers/plugins/RabbitMqPlugin.php +++ b/airtime_mvc/application/controllers/plugins/RabbitMqPlugin.php @@ -4,6 +4,9 @@ class RabbitMqPlugin extends Zend_Controller_Plugin_Abstract { public function dispatchLoopShutdown() { - RabbitMq::PushScheduleFinal(); + if (RabbitMq::$doPush) { + $md = array('schedule' => Schedule::GetScheduledPlaylists()); + RabbitMq::SendMessageToPypo("update_schedule", $md); + } } } \ No newline at end of file diff --git a/airtime_mvc/application/models/Preference.php b/airtime_mvc/application/models/Preference.php index dc4f6792c..ef222abfb 100644 --- a/airtime_mvc/application/models/Preference.php +++ b/airtime_mvc/application/models/Preference.php @@ -59,7 +59,6 @@ class Application_Model_Preference $result = $CC_DBC->GetOne($sql); return $result; } - } public static function GetHeadTitle(){ @@ -263,6 +262,9 @@ class Application_Model_Preference public static function SetTimezone($timezone){ Application_Model_Preference::SetValue("timezone", $timezone); + date_default_timezone_set($timezone); + $md = array("timezone" => $timezone); + RabbitMq::SendMessageToPypo("update_timezone", $md); } public static function GetTimezone(){ diff --git a/airtime_mvc/application/models/RabbitMq.php b/airtime_mvc/application/models/RabbitMq.php index 514f8aecf..d93a9d1bc 100644 --- a/airtime_mvc/application/models/RabbitMq.php +++ b/airtime_mvc/application/models/RabbitMq.php @@ -3,7 +3,7 @@ require_once 'php-amqplib/amqp.inc'; class RabbitMq { - static private $doPush = FALSE; + static public $doPush = FALSE; /** * Sets a flag to push the schedule at the end of the request. @@ -17,7 +17,7 @@ class RabbitMq * Will push the schedule in the range from 24 hours ago to 24 hours * in the future. */ - public static function PushScheduleFinal() +/* public static function PushScheduleFinal() { global $CC_CONFIG; if (RabbitMq::$doPush) { @@ -42,6 +42,32 @@ class RabbitMq self::SendMessageToShowRecorder("update_schedule"); } + } */ + + public static function SendMessageToPypo($event_type, $md) + { + global $CC_CONFIG; + + $md["event_type"] = $event_type; + + $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); + + $data = json_encode($md); + $msg = new AMQPMessage($data, array('content_type' => 'text/plain')); + + $channel->basic_publish($msg, $EXCHANGE); + $channel->close(); + $conn->close(); + + self::SendMessageToShowRecorder("update_schedule"); } public static function SendMessageToMediaMonitor($event_type, $md) diff --git a/airtime_mvc/application/models/tests/populator.php b/airtime_mvc/application/models/tests/populator.php index 4a83e6ff0..38f79bb24 100644 --- a/airtime_mvc/application/models/tests/populator.php +++ b/airtime_mvc/application/models/tests/populator.php @@ -96,7 +96,11 @@ while ($showTime < $endDate) { } $showNumber = $showNumber + 1; } -RabbitMq::PushScheduleFinal(); + +if (RabbitMq::$doPush) { + $md = array('schedule' => Schedule::GetScheduledPlaylists()); + RabbitMq::SendMessageToPypo("update_schedule", $md); +} diff --git a/python_apps/pypo/pypofetch.py b/python_apps/pypo/pypofetch.py index 8ce94420e..dcf0fc81c 100755 --- a/python_apps/pypo/pypofetch.py +++ b/python_apps/pypo/pypofetch.py @@ -55,6 +55,11 @@ def handle_message(body, message): if(command == 'update_schedule'): SCHEDULE_PUSH_MSG = m['schedule'] + elif (command == 'update_timezone'): + logger.info("Setting timezone to %s", m['timezone']) + os.environ['TZ'] = m['timezone'] + time.tzset() + # ACK the message to take it off the queue message.ack()