From 245d9a95d0e3e23d70e604ae73a4a2720af4ba46 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Tue, 11 Sep 2012 11:12:58 -0400 Subject: [PATCH] CC-4389: Convert all PHP errors to throw exceptions instead -don't throw exception for suppressed errors. --- airtime_mvc/application/models/RabbitMq.php | 54 ++++++--------------- airtime_mvc/public/index.php | 11 +++-- 2 files changed, 21 insertions(+), 44 deletions(-) diff --git a/airtime_mvc/application/models/RabbitMq.php b/airtime_mvc/application/models/RabbitMq.php index 797cdb145..a01de51c6 100644 --- a/airtime_mvc/application/models/RabbitMq.php +++ b/airtime_mvc/application/models/RabbitMq.php @@ -13,12 +13,10 @@ class Application_Model_RabbitMq Application_Model_RabbitMq::$doPush = TRUE; } - public static function SendMessageToPypo($event_type, $md) + private static function sendMessage($exchange, $data) { global $CC_CONFIG; - $md["event_type"] = $event_type; - $conn = new AMQPConnection($CC_CONFIG["rabbitmq"]["host"], $CC_CONFIG["rabbitmq"]["port"], $CC_CONFIG["rabbitmq"]["user"], @@ -39,62 +37,40 @@ class Application_Model_RabbitMq $conn->close(); } - public static function SendMessageToMediaMonitor($event_type, $md) + 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"], - $CC_CONFIG["rabbitmq"]["vhost"]); - $channel = $conn->channel(); - $channel->access_request($CC_CONFIG["rabbitmq"]["vhost"], false, false, - true, true); + $exchange = 'airtime-pypo'; + $data = json_encode($md, JSON_FORCE_OBJECT); + self::sendMessage($exchange, $data); + } - $EXCHANGE = 'airtime-media-monitor'; - $channel->exchange_declare($EXCHANGE, 'direct', false, true); + public static function SendMessageToMediaMonitor($event_type, $md) + { + $md["event_type"] = $event_type; + $exchange = 'airtime-media-monitor'; $data = json_encode($md); - $msg = new AMQPMessage($data, array('content_type' => 'text/plain')); - - $channel->basic_publish($msg, $EXCHANGE); - $channel->close(); - $conn->close(); + self::sendMessage($exchange, $data); } public static function SendMessageToShowRecorder($event_type) { - global $CC_CONFIG; - - $conn = new AMQPConnection($CC_CONFIG["rabbitmq"]["host"], - $CC_CONFIG["rabbitmq"]["port"], - $CC_CONFIG["rabbitmq"]["user"], - $CC_CONFIG["rabbitmq"]["password"], - $CC_CONFIG["rabbitmq"]["vhost"]); - $channel = $conn->channel(); - $channel->access_request($CC_CONFIG["rabbitmq"]["vhost"], false, false, - true, true); - - $EXCHANGE = 'airtime-pypo'; - $channel->exchange_declare($EXCHANGE, 'direct', false, true); + $exchange = 'airtime-pypo'; $now = new DateTime("@".time()); //in UTC timezone $end_timestamp = new DateTime("@".(time() + 3600*2)); //in UTC timezone + $temp = array(); $temp['event_type'] = $event_type; $temp['server_timezone'] = Application_Model_Preference::GetTimezone(); if ($event_type == "update_recorder_schedule") { $temp['shows'] = Application_Model_Show::getShows($now, - $end_timestamp, $onlyRecord=TRUE); + $end_timestamp, $onlyRecord=true); } $data = json_encode($temp); - $msg = new AMQPMessage($data, array('content_type' => 'text/plain')); - $channel->basic_publish($msg, $EXCHANGE); - $channel->close(); - $conn->close(); + self::sendMessage($exchange, $data); } } diff --git a/airtime_mvc/public/index.php b/airtime_mvc/public/index.php index fba26a71a..b6484a3cf 100644 --- a/airtime_mvc/public/index.php +++ b/airtime_mvc/public/index.php @@ -4,7 +4,13 @@ error_reporting(E_ALL|E_STRICT); function exception_error_handler($errno, $errstr, $errfile, $errline) { + //Check if the statement that threw this error wanted its errors to be + //suppressed. If so then return without with throwing exception. + if (0 === error_reporting()) { + return; + } throw new ErrorException($errstr, $errno, 0, $errfile, $errline); + return false; } set_error_handler("exception_error_handler"); @@ -48,11 +54,6 @@ Logging::setLogPath('/var/log/airtime/zendphp.log'); // Create application, bootstrap, and run try { - $application = new Zend_Application( - APPLICATION_ENV, - APPLICATION_PATH . '/configs/application.ini' - ); - $sapi_type = php_sapi_name(); if (substr($sapi_type, 0, 3) == 'cli') { set_include_path(APPLICATION_PATH . PATH_SEPARATOR . get_include_path());