From 4bdd89f747af4d75d098b6e27861b423f67f4c82 Mon Sep 17 00:00:00 2001 From: denise Date: Mon, 18 Mar 2013 12:34:27 -0400 Subject: [PATCH] CC-4961: Show linking Fixed edit show start/end time bug --- .../application/services/CalendarService.php | 10 ++++- .../services/ShowInstanceService.php | 39 ++++++++++++------- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/airtime_mvc/application/services/CalendarService.php b/airtime_mvc/application/services/CalendarService.php index a03fd734b..9988c149b 100644 --- a/airtime_mvc/application/services/CalendarService.php +++ b/airtime_mvc/application/services/CalendarService.php @@ -190,7 +190,9 @@ class Application_Service_CalendarService if ($isUpdate) { $this->service_showInstances->deleteInvalidInstances($showData, $isRecorded, $repeatType); - $this->service_showInstances->updateScheduleStatus($showId); + // updates cc_show_instances start/end times, and updates + // schedule start/end times + $this->service_showInstances->applyShowStartEndDifference($showData, $showId); $this->service_showInstances->deleteRebroadcastInstances($showId); $this->service_showDays->deleteShowDays(); $this->service_show->deleteShowHosts($showId); @@ -213,6 +215,12 @@ class Application_Service_CalendarService //create new ccShowInstances $this->service_showInstances->delegateShowInstanceCreation($showId, $isRebroadcast, $isUpdate); + //after all instances have been deleted/updated, we need to update + //the schedule playout status + if ($isUpdate) { + $this->service_showInstances->updateScheduleStatus($showId); + } + $con->commit(); Application_Model_RabbitMq::PushSchedule(); } catch (Exception $e) { diff --git a/airtime_mvc/application/services/ShowInstanceService.php b/airtime_mvc/application/services/ShowInstanceService.php index b6701e705..93072f2d1 100644 --- a/airtime_mvc/application/services/ShowInstanceService.php +++ b/airtime_mvc/application/services/ShowInstanceService.php @@ -68,12 +68,6 @@ class Application_Service_ShowInstanceService $ccShowInstance = new CcShowInstances(); if ($isUpdate) { $ccShowInstance = $this->getInstance($utcStartDateTime, $showDay->getDbShowId()); - //update schedule start times - //ccShowDays object of the show being edited - $currentShowDay = $this->service_showDays->getCurrentShowDay(); - $diff = $this->calculateShowStartDiff($utcStartDateTime, - $currentShowDay->getUTCStartDateAndTime()); - Application_Service_ScheduleService::updateScheduleStartTime(array($ccShowInstance->getDbId()), $diff); } $ccShowInstance->setDbShowId($showDay->getDbShowId()); $ccShowInstance->setDbStarts($utcStartDateTime); @@ -126,15 +120,22 @@ class Application_Service_ShowInstanceService ( is_null($utcLastShowDateTime) || $utcStartDateTime->getTimestamp() < $utcLastShowDateTime->getTimestamp()) ) { - $ccShowInstance = new CcShowInstances(); - if ($isUpdate) { + /* There may not always be an instance when editing a show + * This will be the case when we are adding a new show day to + * a repeating show + */ + if ($isUpdate && $this->hasInstance($utcStartDateTime, $show_id)) { $ccShowInstance = $this->getInstance($utcStartDateTime, $show_id); + $newInstance = false; + } else { + $newInstance = true; + $ccShowInstance = new CcShowInstances(); } /* When editing the start/end time of a repeating show, we don't want to * change shows that started in the past. So check the start time. */ - if (!$isUpdate || $ccShowInstance->getDbStarts() > gmdate("Y-m-d H:i:s")) { + if ($newInstance || $ccShowInstance->getDbStarts() > gmdate("Y-m-d H:i:s")) { $ccShowInstance->setDbShowId($show_id); $ccShowInstance->setDbStarts($utcStartDateTime); $ccShowInstance->setDbEnds($utcEndDateTime); @@ -294,10 +295,15 @@ SQL; ->find(); if ($ccShowInstance->isEmpty()) { - throw new Exception("Show instance not found"); + return false; + } else { + return $ccShowInstance[0]; } + } - return $ccShowInstance[0]; + public function hasInstance($starts, $showId) + { + return $this->getInstance($starts, $showId) ? true : false; } public function getAllFutureInstanceIds($showId) @@ -458,9 +464,14 @@ SQL; } } }//if repeats + } - /*$newStartDateTime = new DateTime($showData["add_show_start_date"]." ". - $showData["add_show_start_time"], + public function applyShowStartEndDifference($showData, $showId) + { + $currentShowDay = $this->service_showDays->getCurrentShowDay(); + + $newStartDateTime = new DateTime($showData["add_show_start_date"]." ". + $showData["add_show_start_time"], new DateTimeZone(Application_Model_Preference::GetTimezone())); $diff = $this->calculateShowStartDiff($newStartDateTime, @@ -468,7 +479,7 @@ SQL; $this->updateInstanceStartEndTime($showId, $diff); $instanceIds = $this->getAllFutureInstanceIds($showId); - Application_Service_ScheduleService::updateScheduleStartTime($instanceIds, $diff);*/ + Application_Service_ScheduleService::updateScheduleStartTime($instanceIds, $diff); } /**