diff --git a/airtime_mvc/application/common/DateHelper.php b/airtime_mvc/application/common/DateHelper.php index f12985804..a5792f0a9 100644 --- a/airtime_mvc/application/common/DateHelper.php +++ b/airtime_mvc/application/common/DateHelper.php @@ -213,7 +213,7 @@ class Application_Common_DateHelper $dateTime = new DateTime($p_dateString, new DateTimeZone($timezone)); } else { - $dateTime = new DateTime($p_dateString, new DateTimeZone(date_default_timezone_get())); + $dateTime = new DateTime($p_dateString, new DateTimeZone(Application_Model_Preference::GetTimezone())); } $dateTime->setTimezone(new DateTimeZone("UTC")); diff --git a/airtime_mvc/application/services/CalendarService.php b/airtime_mvc/application/services/CalendarService.php index 21b36df79..ca0b59d27 100644 --- a/airtime_mvc/application/services/CalendarService.php +++ b/airtime_mvc/application/services/CalendarService.php @@ -244,8 +244,8 @@ class Application_Service_CalendarService $today_timestamp = time(); - $startsDateTime = new DateTime($this->ccShowInstance->getDbStarts(), new DateTimeZone("UTC")); - $endsDateTime = new DateTime($this->ccShowInstance->getDbEnds(), new DateTimeZone("UTC")); + $startsDateTime = $this->ccShowInstance->getDbStarts(null); + $endsDateTime = $this->ccShowInstance->getDbEnds(null); if ($today_timestamp > $startsDateTime->getTimestamp()) { throw new Exception(_("Can't move a past show")); @@ -315,13 +315,16 @@ class Application_Service_CalendarService $con = Propel::getConnection(); $con->beginTransaction(); + //new starts,ends are in UTC list($newStartsDateTime, $newEndsDateTime) = $this->validateShowMove( $deltaDay, $deltaMin); + + $oldStartDateTime = $this->ccShowInstance->getDbStarts(null); $this->ccShowInstance ->setDbStarts($newStartsDateTime) ->setDbEnds($newEndsDateTime) - ->save(); + ->save($con); if (!$this->ccShowInstance->getCcShow()->isRebroadcast()) { //we can get the first show day because we know the show is @@ -331,11 +334,13 @@ class Application_Service_CalendarService $ccShowDay ->setDbFirstShow($newStartsDateTime->setTimezone($showTimezone)->format("Y-m-d")) ->setDbStartTime($newStartsDateTime->format("H:i")) - ->save(); + ->save($con); } - + + $diff = $newStartsDateTime->getTimestamp() - $oldStartDateTime->getTimestamp(); + Application_Service_SchedulerService::updateScheduleStartTime( - array($this->ccShowInstance->getDbId()), null, $newStartsDateTime); + array($this->ccShowInstance->getDbId()), $diff); $con->commit(); Application_Model_RabbitMq::PushSchedule(); diff --git a/airtime_mvc/application/services/SchedulerService.php b/airtime_mvc/application/services/SchedulerService.php index ee20ee360..60206c112 100644 --- a/airtime_mvc/application/services/SchedulerService.php +++ b/airtime_mvc/application/services/SchedulerService.php @@ -44,47 +44,31 @@ class Application_Service_SchedulerService * Applies the show start difference to any scheduled items * * @param $instanceIds - * @param $diff - * @param $newStart + * @param $diff (integer, difference between unix epoch in seconds) */ - public static function updateScheduleStartTime($instanceIds, $diff=null, $newStart=null) + public static function updateScheduleStartTime($instanceIds, $diff) { $con = Propel::getConnection(); if (count($instanceIds) > 0) { $showIdList = implode(",", $instanceIds); - if (is_null($diff)) { - $ccSchedule = CcScheduleQuery::create() - ->filterByDbInstanceId($instanceIds, Criteria::IN) - ->orderByDbStarts() - ->limit(1) - ->findOne(); - - if (!is_null($ccSchedule)) { - $scheduleStartsEpoch = strtotime($ccSchedule->getDbStarts()); - $showStartsEpoch = strtotime($newStart->format("Y-m-d H:i:s")); - - $diff = $showStartsEpoch - $scheduleStartsEpoch; - } - } - $ccSchedules = CcScheduleQuery::create() ->filterByDbInstanceId($instanceIds, Criteria::IN) - ->find(); + ->find($con); $interval = new DateInterval("PT".abs($diff)."S"); if ($diff < 0) { $interval->invert = 1; } foreach ($ccSchedules as $ccSchedule) { - $start = new DateTime($ccSchedule->getDbStarts()); + $start = $ccSchedule->getDbStarts(null); $newStart = $start->add($interval); - $end = new DateTime($ccSchedule->getDbEnds()); + $end = $ccSchedule->getDbEnds(null); $newEnd = $end->add($interval); $ccSchedule - ->setDbStarts($newStart->format("Y-m-d H:i:s")) - ->setDbEnds($newEnd->format("Y-m-d H:i:s")) - ->save(); + ->setDbStarts($newStart) + ->setDbEnds($newEnd) + ->save($con); } } }