2011-03-22 14:55:33 +01:00
|
|
|
<?php
|
|
|
|
|
2024-01-07 13:59:02 +01:00
|
|
|
use PhpAmqpLib\Connection\AMQPStreamConnection;
|
|
|
|
use PhpAmqpLib\Message\AMQPMessage;
|
|
|
|
|
2011-09-26 21:32:56 +02:00
|
|
|
class Application_Model_RabbitMq
|
2011-03-22 14:55:33 +01:00
|
|
|
{
|
2012-09-15 00:20:46 +02:00
|
|
|
public static $doPush = false;
|
2011-03-24 04:24:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a flag to push the schedule at the end of the request.
|
|
|
|
*/
|
2012-07-16 03:17:13 +02:00
|
|
|
public static function PushSchedule()
|
|
|
|
{
|
2012-09-15 00:20:46 +02:00
|
|
|
self::$doPush = true;
|
2011-03-24 04:24:06 +01:00
|
|
|
}
|
2011-03-22 14:55:33 +01:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
private static function sendMessage($exchange, $exchangeType, $autoDeleteExchange, $data, $queue = '')
|
2011-08-12 21:36:00 +02:00
|
|
|
{
|
2013-01-14 22:16:14 +01:00
|
|
|
$CC_CONFIG = Config::getConfig();
|
2011-08-12 21:36:00 +02:00
|
|
|
|
2024-01-07 13:59:02 +01:00
|
|
|
$conn = new AMQPStreamConnection(
|
2021-10-11 16:10:47 +02:00
|
|
|
$CC_CONFIG['rabbitmq']['host'],
|
|
|
|
$CC_CONFIG['rabbitmq']['port'],
|
|
|
|
$CC_CONFIG['rabbitmq']['user'],
|
|
|
|
$CC_CONFIG['rabbitmq']['password'],
|
|
|
|
$CC_CONFIG['rabbitmq']['vhost']
|
|
|
|
);
|
2013-03-04 21:22:09 +01:00
|
|
|
|
|
|
|
if (!isset($conn)) {
|
2021-10-11 16:10:47 +02:00
|
|
|
throw new Exception('Cannot connect to RabbitMQ server');
|
2013-03-04 21:22:09 +01:00
|
|
|
}
|
|
|
|
|
2011-08-12 21:36:00 +02:00
|
|
|
$channel = $conn->channel();
|
2021-10-11 16:10:47 +02:00
|
|
|
$channel->access_request(
|
|
|
|
$CC_CONFIG['rabbitmq']['vhost'],
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
true
|
|
|
|
);
|
2011-08-12 21:36:00 +02:00
|
|
|
|
2022-03-14 11:15:04 +01:00
|
|
|
// I'm pretty sure we DON'T want to autodelete ANY exchanges but I'm keeping the code
|
|
|
|
// the way it is just so I don't accidentally break anything when I add the Analyzer code in. -- Albert, March 13, 2014
|
2014-03-13 18:35:48 +01:00
|
|
|
$channel->exchange_declare($exchange, $exchangeType, false, true, $autoDeleteExchange);
|
2011-08-12 21:36:00 +02:00
|
|
|
|
2024-01-07 13:59:02 +01:00
|
|
|
$msg = new AMQPMessage($data, ['content_type' => 'text/plain']);
|
2011-08-12 21:36:00 +02:00
|
|
|
|
2012-09-11 17:20:42 +02:00
|
|
|
$channel->basic_publish($msg, $exchange);
|
2011-08-12 21:36:00 +02:00
|
|
|
$channel->close();
|
|
|
|
$conn->close();
|
2011-03-22 14:55:33 +01:00
|
|
|
}
|
|
|
|
|
2012-09-11 17:12:58 +02:00
|
|
|
public static function SendMessageToPypo($event_type, $md)
|
2011-05-05 16:55:14 +02:00
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
$md['event_type'] = $event_type;
|
2011-06-17 17:54:36 +02:00
|
|
|
|
2012-09-11 17:12:58 +02:00
|
|
|
$exchange = 'airtime-pypo';
|
|
|
|
$data = json_encode($md, JSON_FORCE_OBJECT);
|
2014-03-13 18:35:48 +01:00
|
|
|
self::sendMessage($exchange, 'direct', true, $data);
|
2012-09-11 17:12:58 +02:00
|
|
|
}
|
2011-05-05 16:55:14 +02:00
|
|
|
|
2012-09-11 17:12:58 +02:00
|
|
|
public static function SendMessageToMediaMonitor($event_type, $md)
|
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
$md['event_type'] = $event_type;
|
2011-05-05 16:55:14 +02:00
|
|
|
|
2018-01-24 08:20:51 +01:00
|
|
|
$exchange = 'airtime-analyzer';
|
2011-05-05 16:55:14 +02:00
|
|
|
$data = json_encode($md);
|
2014-03-13 18:35:48 +01:00
|
|
|
self::sendMessage($exchange, 'direct', true, $data);
|
2011-05-05 16:55:14 +02:00
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2011-07-23 18:30:36 +02:00
|
|
|
public static function SendMessageToShowRecorder($event_type)
|
|
|
|
{
|
2012-09-11 17:12:58 +02:00
|
|
|
$exchange = 'airtime-pypo';
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2022-03-14 11:15:04 +01:00
|
|
|
$now = new DateTime('@' . time()); // in UTC timezone
|
|
|
|
$end_timestamp = new DateTime('@' . (time() + 3600 * 2)); // in UTC timezone
|
2011-08-16 22:36:31 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$temp = [];
|
2011-07-25 22:24:00 +02:00
|
|
|
$temp['event_type'] = $event_type;
|
2011-10-05 23:27:00 +02:00
|
|
|
$temp['server_timezone'] = Application_Model_Preference::GetTimezone();
|
2021-10-11 16:10:47 +02:00
|
|
|
if ($event_type == 'update_recorder_schedule') {
|
|
|
|
$temp['shows'] = Application_Model_Show::getShows(
|
|
|
|
$now,
|
|
|
|
$end_timestamp,
|
|
|
|
$onlyRecord = true
|
|
|
|
);
|
2011-07-25 22:24:00 +02:00
|
|
|
}
|
|
|
|
$data = json_encode($temp);
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2014-03-13 18:35:48 +01:00
|
|
|
self::sendMessage($exchange, 'direct', true, $data);
|
2011-07-23 18:30:36 +02:00
|
|
|
}
|
2014-03-17 15:19:39 +01:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
public static function SendMessageToAnalyzer(
|
|
|
|
$tmpFilePath,
|
|
|
|
$importedStorageDirectory,
|
|
|
|
$originalFilename,
|
2023-02-10 22:55:54 +01:00
|
|
|
$fileId,
|
|
|
|
$fileTrackTypeId
|
2021-10-11 16:10:47 +02:00
|
|
|
) {
|
2017-07-18 22:27:19 +02:00
|
|
|
$config = Config::getConfig();
|
|
|
|
|
2024-01-07 13:59:02 +01:00
|
|
|
$conn = new AMQPStreamConnection(
|
2021-10-11 16:10:47 +02:00
|
|
|
$config['rabbitmq']['host'],
|
|
|
|
$config['rabbitmq']['port'],
|
|
|
|
$config['rabbitmq']['user'],
|
|
|
|
$config['rabbitmq']['password'],
|
|
|
|
$config['rabbitmq']['vhost']
|
|
|
|
);
|
|
|
|
|
2014-03-13 16:14:30 +01:00
|
|
|
$exchange = 'airtime-uploads';
|
2014-04-01 18:07:29 +02:00
|
|
|
$exchangeType = 'topic';
|
|
|
|
$queue = 'airtime-uploads';
|
|
|
|
$autoDeleteExchange = false;
|
2022-07-26 14:19:22 +02:00
|
|
|
|
|
|
|
$data['file_id'] = $fileId;
|
2014-03-13 18:35:48 +01:00
|
|
|
$data['tmp_file_path'] = $tmpFilePath;
|
2014-03-17 15:19:39 +01:00
|
|
|
$data['import_directory'] = $importedStorageDirectory;
|
|
|
|
$data['original_filename'] = $originalFilename;
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2023-02-20 14:16:36 +01:00
|
|
|
$options = new stdClass();
|
2023-02-10 22:55:54 +01:00
|
|
|
|
|
|
|
if ($fileTrackTypeId) {
|
|
|
|
$fileTrackType = new Application_Model_Tracktype($fileTrackTypeId);
|
2023-02-21 07:56:14 +01:00
|
|
|
$options->analyze_cue_points = $fileTrackType->getAnalyzeCuePoints();
|
2023-02-10 22:55:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$data['options'] = $options;
|
|
|
|
|
2014-03-13 18:35:48 +01:00
|
|
|
$jsonData = json_encode($data);
|
2022-03-14 11:15:04 +01:00
|
|
|
// self::sendMessage($exchange, 'topic', false, $jsonData, 'airtime-uploads');
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2014-04-01 18:07:29 +02:00
|
|
|
if (!isset($conn)) {
|
2021-10-11 16:10:47 +02:00
|
|
|
throw new Exception('Cannot connect to RabbitMQ server');
|
2014-04-01 18:07:29 +02:00
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2014-04-01 18:07:29 +02:00
|
|
|
$channel = $conn->channel();
|
2021-10-11 16:10:47 +02:00
|
|
|
$channel->access_request(
|
|
|
|
$config['rabbitmq']['vhost'],
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2022-03-14 11:15:04 +01:00
|
|
|
// I'm pretty sure we DON'T want to autodelete ANY exchanges but I'm keeping the code
|
|
|
|
// the way it is just so I don't accidentally break anything when I add the Analyzer code in. -- Albert, March 13, 2014
|
2014-04-01 18:07:29 +02:00
|
|
|
$channel->exchange_declare($exchange, $exchangeType, false, true, $autoDeleteExchange);
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2024-01-07 13:59:02 +01:00
|
|
|
$msg = new AMQPMessage($jsonData, ['content_type' => 'text/plain']);
|
2015-11-13 16:53:47 +01:00
|
|
|
|
2014-04-01 18:07:29 +02:00
|
|
|
$channel->basic_publish($msg, $exchange);
|
2014-04-02 23:27:10 +02:00
|
|
|
$channel->close();
|
|
|
|
$conn->close();
|
2011-07-23 18:30:36 +02:00
|
|
|
}
|
2011-03-22 14:55:33 +01:00
|
|
|
}
|