CC-5594 : Remove all date_default_timezone_get()
updating move show code to work with the user's timezone. unified method signature for updateScheduleStartTime to always use the $diff param.
This commit is contained in:
parent
061897a58b
commit
7e9ca3e950
|
@ -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"));
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue