CC-4389: Convert all PHP errors to throw exceptions instead

-don't throw exception for suppressed errors.
This commit is contained in:
Martin Konecny 2012-09-11 11:12:58 -04:00
parent 1635842b81
commit 245d9a95d0
2 changed files with 21 additions and 44 deletions

View File

@ -13,12 +13,10 @@ class Application_Model_RabbitMq
Application_Model_RabbitMq::$doPush = TRUE; Application_Model_RabbitMq::$doPush = TRUE;
} }
public static function SendMessageToPypo($event_type, $md) private static function sendMessage($exchange, $data)
{ {
global $CC_CONFIG; global $CC_CONFIG;
$md["event_type"] = $event_type;
$conn = new AMQPConnection($CC_CONFIG["rabbitmq"]["host"], $conn = new AMQPConnection($CC_CONFIG["rabbitmq"]["host"],
$CC_CONFIG["rabbitmq"]["port"], $CC_CONFIG["rabbitmq"]["port"],
$CC_CONFIG["rabbitmq"]["user"], $CC_CONFIG["rabbitmq"]["user"],
@ -39,62 +37,40 @@ class Application_Model_RabbitMq
$conn->close(); $conn->close();
} }
public static function SendMessageToMediaMonitor($event_type, $md) public static function SendMessageToPypo($event_type, $md)
{ {
global $CC_CONFIG;
$md["event_type"] = $event_type; $md["event_type"] = $event_type;
$conn = new AMQPConnection($CC_CONFIG["rabbitmq"]["host"], $exchange = 'airtime-pypo';
$CC_CONFIG["rabbitmq"]["port"], $data = json_encode($md, JSON_FORCE_OBJECT);
$CC_CONFIG["rabbitmq"]["user"], self::sendMessage($exchange, $data);
$CC_CONFIG["rabbitmq"]["password"], }
$CC_CONFIG["rabbitmq"]["vhost"]);
$channel = $conn->channel();
$channel->access_request($CC_CONFIG["rabbitmq"]["vhost"], false, false,
true, true);
$EXCHANGE = 'airtime-media-monitor'; public static function SendMessageToMediaMonitor($event_type, $md)
$channel->exchange_declare($EXCHANGE, 'direct', false, true); {
$md["event_type"] = $event_type;
$exchange = 'airtime-media-monitor';
$data = json_encode($md); $data = json_encode($md);
$msg = new AMQPMessage($data, array('content_type' => 'text/plain')); self::sendMessage($exchange, $data);
$channel->basic_publish($msg, $EXCHANGE);
$channel->close();
$conn->close();
} }
public static function SendMessageToShowRecorder($event_type) public static function SendMessageToShowRecorder($event_type)
{ {
global $CC_CONFIG; $exchange = 'airtime-pypo';
$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);
$now = new DateTime("@".time()); //in UTC timezone $now = new DateTime("@".time()); //in UTC timezone
$end_timestamp = new DateTime("@".(time() + 3600*2)); //in UTC timezone $end_timestamp = new DateTime("@".(time() + 3600*2)); //in UTC timezone
$temp = array();
$temp['event_type'] = $event_type; $temp['event_type'] = $event_type;
$temp['server_timezone'] = Application_Model_Preference::GetTimezone(); $temp['server_timezone'] = Application_Model_Preference::GetTimezone();
if ($event_type == "update_recorder_schedule") { if ($event_type == "update_recorder_schedule") {
$temp['shows'] = Application_Model_Show::getShows($now, $temp['shows'] = Application_Model_Show::getShows($now,
$end_timestamp, $onlyRecord=TRUE); $end_timestamp, $onlyRecord=true);
} }
$data = json_encode($temp); $data = json_encode($temp);
$msg = new AMQPMessage($data, array('content_type' => 'text/plain'));
$channel->basic_publish($msg, $EXCHANGE); self::sendMessage($exchange, $data);
$channel->close();
$conn->close();
} }
} }

View File

@ -4,7 +4,13 @@ error_reporting(E_ALL|E_STRICT);
function exception_error_handler($errno, $errstr, $errfile, $errline) 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); throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
return false;
} }
set_error_handler("exception_error_handler"); set_error_handler("exception_error_handler");
@ -48,11 +54,6 @@ Logging::setLogPath('/var/log/airtime/zendphp.log');
// Create application, bootstrap, and run // Create application, bootstrap, and run
try { try {
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
if (substr($sapi_type, 0, 3) == 'cli') { if (substr($sapi_type, 0, 3) == 'cli') {
set_include_path(APPLICATION_PATH . PATH_SEPARATOR . get_include_path()); set_include_path(APPLICATION_PATH . PATH_SEPARATOR . get_include_path());