From 846e08699e0daac8e844c71836e447b6e9ac1138 Mon Sep 17 00:00:00 2001 From: martin Date: Thu, 18 Aug 2011 18:13:43 -0400 Subject: [PATCH] CC-2628: update a repeated show start time cause the show to get corrupted -disabled dragging + dropping repeated show instances --- .../controllers/ScheduleController.php | 12 ++-- airtime_mvc/application/models/RabbitMq.php | 32 ----------- airtime_mvc/application/models/Schedule.php | 5 +- airtime_mvc/application/models/Shows.php | 55 ++++++++++++------- 4 files changed, 42 insertions(+), 62 deletions(-) diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index 970c9fc1d..1dfd4bcb9 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -80,19 +80,19 @@ class ScheduleController extends Zend_Controller_Action public function moveShowAction() { $deltaDay = $this->_getParam('day'); - $deltaMin = $this->_getParam('min'); - $showInstanceId = $this->_getParam('showInstanceId'); + $deltaMin = $this->_getParam('min'); + $showInstanceId = $this->_getParam('showInstanceId'); $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new User($userInfo->id); if($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) { - $show = new ShowInstance($showInstanceId); - $error = $show->moveShow($deltaDay, $deltaMin); + $show = new ShowInstance($showInstanceId); + $error = $show->moveShow($deltaDay, $deltaMin); } - if(isset($error)) - $this->view->error = $error; + if(isset($error)) + $this->view->error = $error; } diff --git a/airtime_mvc/application/models/RabbitMq.php b/airtime_mvc/application/models/RabbitMq.php index 9cb3cb166..daf9fa123 100644 --- a/airtime_mvc/application/models/RabbitMq.php +++ b/airtime_mvc/application/models/RabbitMq.php @@ -12,38 +12,6 @@ class RabbitMq 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 PushScheduleFinal() - { - global $CC_CONFIG; - 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); - - $temp['event_type'] = "update_schedule"; - $temp['schedule'] = Schedule::GetScheduledPlaylists(); - $data = json_encode($temp); - $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 SendMessageToPypo($event_type, $md) { global $CC_CONFIG; diff --git a/airtime_mvc/application/models/Schedule.php b/airtime_mvc/application/models/Schedule.php index 46bcdc7ec..4a0e3b176 100644 --- a/airtime_mvc/application/models/Schedule.php +++ b/airtime_mvc/application/models/Schedule.php @@ -657,13 +657,13 @@ class Schedule { global $CC_CONFIG, $CC_DBC; if (is_null($p_fromDateTime)) { - $t1 = new DateTime("now", new DateTimeZone("UTC")); + $t1 = new DateTime("@".time()); $range_start = $t1->format("Y-m-d H:i:s"); } else { $range_start = Schedule::PypoTimeToAirtimeTime($p_fromDateTime); } if (is_null($p_fromDateTime)) { - $t2 = new DateTime("now", new DateTimeZone("UTC")); + $t2 = new DateTime("@".time()); $t2->add(new DateInterval("PT24H")); $range_end = $t2->format("Y-m-d H:i:s"); } else { @@ -686,7 +686,6 @@ class Schedule { $timestamp = strtotime($start); $playlists[$pkey]['source'] = "PLAYLIST"; $playlists[$pkey]['x_ident'] = $dx['group_id']; - //$playlists[$pkey]['subtype'] = '1'; // Just needs to be between 1 and 4 inclusive $playlists[$pkey]['timestamp'] = $timestamp; $playlists[$pkey]['duration'] = $dx['clip_length']; $playlists[$pkey]['played'] = '0'; diff --git a/airtime_mvc/application/models/Shows.php b/airtime_mvc/application/models/Shows.php index b5895d111..ae15fcceb 100644 --- a/airtime_mvc/application/models/Shows.php +++ b/airtime_mvc/application/models/Shows.php @@ -724,26 +724,28 @@ class Show { */ public static function create($data) { - - $utcStartDateTime = new DateTime($data['add_show_start_date']." ".$data['add_show_start_time']); - $utcStartDateTime->setTimezone(new DateTimeZone('UTC')); - + + $utcStartDateTime = new DateTime($data['add_show_start_date']." ".$data['add_show_start_time']); + $utcStartDateTime->setTimezone(new DateTimeZone('UTC')); + if ($data['add_show_no_end']) { - $endDateTime = NULL; + $endDate = NULL; } else if ($data['add_show_repeats']) { $endDateTime = new DateTime($data['add_show_end_date']); - $endDateTime->setTimezone(new DateTimeZone('UTC')); + $endDateTime->setTimezone(new DateTimeZone('UTC')); $endDateTime->add(new DateInterval("P1D")); + $endDate = $endDateTime->format("Y-m-d"); } else { $endDateTime = new DateTime($data['add_show_start_date']); - $endDateTime->setTimezone(new DateTimeZone('UTC')); + $endDateTime->setTimezone(new DateTimeZone('UTC')); $endDateTime->add(new DateInterval("P1D")); + $endDate = $endDateTime->format("Y-m-d"); } //only want the day of the week from the start date. - $startDow = date("w", $utcStartDateTime->getTimestamp()); + $startDow = date("w", $utcStartDateTime->getTimestamp()); if (!$data['add_show_repeats']) { $data['add_show_day_check'] = array($startDow); } else if ($data['add_show_repeats'] && $data['add_show_day_check'] == "") { @@ -771,8 +773,8 @@ class Show { $isRecorded = ($data['add_show_record']) ? 1 : 0; if ($data['add_show_id'] != -1){ - $show = new Show($showId); - $show->deletePossiblyInvalidInstances($data, $endDateTime->format("Y-m-d"), $isRecorded, $repeatType); + $show = new Show($showId); + $show->deletePossiblyInvalidInstances($data, $endDate, $isRecorded, $repeatType); } //check if we are adding or updating a show, and if updating @@ -785,7 +787,7 @@ class Show { if ($data['add_show_repeats'] && $data['add_show_repeat_type'] == 2){ $showDay = new CcShowDays(); $showDay->setDbFirstShow($utcStartDateTime->format("Y-m-d")); - $showDay->setDbLastShow($endDateTime->format("Y-m-d")); + $showDay->setDbLastShow($endDate); $showDay->setDbStartTime($utcStartDateTime->format("H:i:s")); $showDay->setDbDuration($data['add_show_duration']); $showDay->setDbRepeatType($repeatType); @@ -800,14 +802,14 @@ class Show { else $daysAdd = $day - $startDow; - $utcStartDateTime->add("P".$daysAdd."d"); + $utcStartDateTime->add(new DateInterval("P".$daysAdd."D")); } - if (is_null($endDateTime) || strtotime($utcStartDateTime->format("Y-m-d")) <= $endDateTime->getTimestamp()) { + if (is_null($endDateTime) || $utcStartDateTime->getTimestamp <= $endDateTime->getTimestamp()) { $showDay = new CcShowDays(); $showDay->setDbFirstShow($utcStartDateTime->format("Y-m-d")); - $showDay->setDbLastShow($endDateTime->format("Y-m-d")); - $showDay->setDbStartTime($utcStartDateTime->format("H:i:s")); + $showDay->setDbLastShow($endDate); + $showDay->setDbStartTime($utcStartDateTime->format("H:i")); $showDay->setDbDuration($data['add_show_duration']); $showDay->setDbDay($day); $showDay->setDbRepeatType($repeatType); @@ -1283,6 +1285,10 @@ class ShowInstance { { return $this->_instanceId; } + + public function getShow(){ + return new Show($this->getShowId()); + } public function isRebroadcast() { @@ -1413,6 +1419,10 @@ class ShowInstance { public function moveShow($deltaDay, $deltaMin) { global $CC_DBC; + + if ($this->getShow()->isRepeating()){ + return "Can't drag and drop repeating shows"; + } $hours = $deltaMin/60; if($hours > 0) @@ -1422,12 +1432,14 @@ class ShowInstance { $mins = abs($deltaMin%60); - $today_timestamp = date("Y-m-d H:i:s"); + $today_timestamp = time(); $starts = $this->getShowStart(); $ends = $this->getShowEnd(); + + $startsDateTime = new DateTime($starts, new DateTimeZone("UTC")); - if(strtotime($today_timestamp) > strtotime($starts)) { - return "can't move a past show"; + if($today_timestamp > $startsDateTime->getTimestamp()) { + return "Can't move a past show"; } $sql = "SELECT timestamp '{$starts}' + interval '{$deltaDay} days' + interval '{$hours}:{$mins}'"; @@ -1436,12 +1448,13 @@ class ShowInstance { $sql = "SELECT timestamp '{$ends}' + interval '{$deltaDay} days' + interval '{$hours}:{$mins}'"; $new_ends = $CC_DBC->GetOne($sql); - if(strtotime($today_timestamp) > strtotime($new_starts)) { - return "can't move show into past"; + $newStartsDateTime = new DateTime($new_starts, new DateTimeZone("UTC")); + if($today_timestamp > $newStartsDateTime->getTimestamp()) { + return "Can't move show into past"; } $overlap = Show::getShows($new_starts, $new_ends, array($this->_instanceId)); - + if(count($overlap) > 0) { return "Should not overlap shows"; }