From 4ca60ca676e3199b90b81a25d203a06e32327f0e Mon Sep 17 00:00:00 2001 From: denise Date: Tue, 30 Apr 2013 13:58:03 -0400 Subject: [PATCH] CC-5074: Editing a linked instance sets incorrect schedule start times --- airtime_mvc/application/models/Scheduler.php | 3 --- .../models/airtime/CcShowInstances.php | 6 ++++++ .../application/services/SchedulerService.php | 9 +++++++-- airtime_mvc/application/services/ShowService.php | 16 ++++++++-------- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/airtime_mvc/application/models/Scheduler.php b/airtime_mvc/application/models/Scheduler.php index 7aec81574..3778cf007 100644 --- a/airtime_mvc/application/models/Scheduler.php +++ b/airtime_mvc/application/models/Scheduler.php @@ -634,10 +634,7 @@ class Application_Model_Scheduler $pstart = microtime(true); //recalculate the start/end times after the inserted items. - Logging::info($excludeIds); - Logging::info($initalStartDT); foreach ($followingSchedItems as $item) { - Logging::info($item); $endTimeDT = $this->findEndTime($nextStartDT, $item->getDbClipLength()); $item->setDbStarts($nextStartDT); diff --git a/airtime_mvc/application/models/airtime/CcShowInstances.php b/airtime_mvc/application/models/airtime/CcShowInstances.php index fb886f684..6fdaaf8a2 100644 --- a/airtime_mvc/application/models/airtime/CcShowInstances.php +++ b/airtime_mvc/application/models/airtime/CcShowInstances.php @@ -185,4 +185,10 @@ class CcShowInstances extends BaseCcShowInstances { return $this->getDbRebroadcast() == 1 ? true : false; } + public function getLocalStartDateTime() + { + $startDT = $this->getDbStarts(null); + return $startDT->setTimezone(new DateTimeZone(Application_Model_Preference::GetTimezone())); + } + } // CcShowInstances diff --git a/airtime_mvc/application/services/SchedulerService.php b/airtime_mvc/application/services/SchedulerService.php index 99f2ae609..b8086e4a2 100644 --- a/airtime_mvc/application/services/SchedulerService.php +++ b/airtime_mvc/application/services/SchedulerService.php @@ -69,9 +69,14 @@ class Application_Service_SchedulerService ->filterByDbInstanceId($instanceIds, Criteria::IN) ->find(); foreach ($ccSchedules as $ccSchedule) { + $interval = new DateInterval("PT".$diff."S"); + $start = new DateTime($ccSchedule->getDbStarts()); + $newStart = $start->add($interval); + $end = new DateTime($ccSchedule->getDbEnds()); + $newEnd = $end->add($interval); $ccSchedule - ->setDbStarts($ccSchedule->getDbStarts() + $diff) - ->setDbEnds($ccSchedule->getDbEnds() + $diff) + ->setDbStarts($newStart->format("Y-m-d H:i:s")) + ->setDbEnds($newEnd->format("Y-m-d H:i:s")) ->save(); } } diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index a829d88bb..f737cf3b6 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -52,18 +52,21 @@ class Application_Service_ShowService //so we can get the original start date and time $oldCcShow = CcShowQuery::create() ->findPk($showData["add_show_id"]); - $currentShowDay = $oldCcShow->getFirstCcShowDay(); //DateTime in user's local time $newStartDateTime = new DateTime($showData["add_show_start_date"]." ". $showData["add_show_start_time"], new DateTimeZone(Application_Model_Preference::GetTimezone())); + $ccShowInstanceOrig = CcShowInstancesQuery::create() + ->findPk($showData["add_show_instance_id"]); $diff = $this->calculateShowStartDiff($newStartDateTime, - $currentShowDay->getLocalStartDateAndTime()); + $ccShowInstanceOrig->getLocalStartDateTime()); - Application_Service_SchedulerService::updateScheduleStartTime( - array($showData["add_show_instance_id"]), $diff); + if ($diff > 0) { + Application_Service_SchedulerService::updateScheduleStartTime( + array($showData["add_show_instance_id"]), $diff); + } /****** UPDATE SCHEDULE START TIME ENDS******/ $this->setCcShow($showData); @@ -89,10 +92,7 @@ class Application_Service_ShowService } //delete the edited instance from the repeating sequence - CcShowInstancesQuery::create() - ->findPk($showData["add_show_instance_id"]) - ->setDbModifiedInstance(true) - ->save(); + $ccShowInstanceOrig->setDbModifiedInstance(true)->save(); $service_showForm = new Application_Service_ShowFormService($showData["add_show_id"]); list($start, $end) = $service_showForm->getNextFutureRepeatShowTime();