CC-5321 : Changing Timezone after Creating shows creates Problems

This commit is contained in:
Naomi Aro 2013-09-06 12:35:31 +02:00
parent 0734a4a98c
commit 5a85fce89d
1 changed files with 41 additions and 40 deletions

View File

@ -169,8 +169,8 @@ class Application_Service_ShowService
} }
/** /**
* *
* Receives a cc_show id and determines whether to create a * Receives a cc_show id and determines whether to create a
* single show instance or repeating show instances * single show instance or repeating show instances
*/ */
public function delegateInstanceCreation($daysAdded=null, $end=null, $fillInstances=false) public function delegateInstanceCreation($daysAdded=null, $end=null, $fillInstances=false)
@ -190,7 +190,7 @@ class Application_Service_ShowService
/* In case the user is moving forward in the calendar and there are /* In case the user is moving forward in the calendar and there are
* linked shows in the schedule we need to keep track of each cc_show * linked shows in the schedule we need to keep track of each cc_show
* so we know which shows need to be filled with content * so we know which shows need to be filled with content
*/ */
$ccShows = array(); $ccShows = array();
foreach ($ccShowDays as $day) { foreach ($ccShowDays as $day) {
@ -273,7 +273,7 @@ class Application_Service_ShowService
} }
/** /**
* *
* Deletes all the cc_show_days entries for a specific show * Deletes all the cc_show_days entries for a specific show
* that is currently being edited. They will get recreated with * that is currently being edited. They will get recreated with
* the new show day specs * the new show day specs
@ -298,12 +298,12 @@ SQL;
/** /**
* TODO: This function is messy. Needs refactoring * TODO: This function is messy. Needs refactoring
* *
* When editing a show we may need to perform some actions to reflect the new specs: * When editing a show we may need to perform some actions to reflect the new specs:
* - Delete some show instances * - Delete some show instances
* - Update duration * - Update duration
* - Update start and end time * - Update start and end time
* *
* @param $showData edit show form values in raw form * @param $showData edit show form values in raw form
* @param $isRecorded value computed from the edit show form * @param $isRecorded value computed from the edit show form
* @param $repeatType value computed from the edit show form * @param $repeatType value computed from the edit show form
@ -342,7 +342,7 @@ SQL;
//if the start date changes, these are the repeat types //if the start date changes, these are the repeat types
//that require show instance deletion //that require show instance deletion
$deleteRepeatTypes = array(REPEAT_BI_WEEKLY, REPEAT_MONTHLY_MONTHLY, $deleteRepeatTypes = array(REPEAT_BI_WEEKLY, REPEAT_MONTHLY_MONTHLY,
REPEAT_MONTHLY_WEEKLY); REPEAT_MONTHLY_WEEKLY);
if (in_array($this->repeatType, $deleteRepeatTypes) && if (in_array($this->repeatType, $deleteRepeatTypes) &&
@ -406,7 +406,7 @@ SQL;
$this->deleteInstancesBeforeDate($showData['add_show_start_date'], $showId); $this->deleteInstancesBeforeDate($showData['add_show_start_date'], $showId);
} }
} }
} }
@ -496,7 +496,7 @@ SQL;
} }
/** /**
* *
* Enter description here ... * Enter description here ...
* @param $daysRemoved array of days (days of the week) removed * @param $daysRemoved array of days (days of the week) removed
* (days of the week are represented numerically * (days of the week are represented numerically
@ -708,10 +708,10 @@ SQL;
} }
/** /**
* *
* Determines what the show end date should be based on * Determines what the show end date should be based on
* the form data * the form data
* *
* @param $showData add/edit show form data * @param $showData add/edit show form data
* @return DateTime object in user's local timezone * @return DateTime object in user's local timezone
*/ */
@ -754,10 +754,10 @@ SQL;
} }
/** /**
* *
* Returns the difference in seconds between a show's new and * Returns the difference in seconds between a show's new and
* old start time * old start time
* *
* @param $newStartDateTime DateTime object * @param $newStartDateTime DateTime object
* @param $oldStartDateTime DateTime object * @param $oldStartDateTime DateTime object
*/ */
@ -767,9 +767,9 @@ SQL;
} }
/** /**
* *
* Updates the start and end time for cc_show_instances * Updates the start and end time for cc_show_instances
* *
* @param $showData edit show form data * @param $showData edit show form data
*/ */
private function updateInstanceStartEndTime($diff) private function updateInstanceStartEndTime($diff)
@ -783,13 +783,13 @@ WHERE show_id = :showId
SQL; SQL;
Application_Common_Database::prepareAndExecute($sql, Application_Common_Database::prepareAndExecute($sql,
array(':diff1' => $diff, ':diff2' => $diff, array(':diff1' => $diff, ':diff2' => $diff,
':showId' => $this->ccShow->getDbId(), ':timestamp' => gmdate("Y-m-d H:i:s")), ':showId' => $this->ccShow->getDbId(), ':timestamp' => gmdate("Y-m-d H:i:s")),
'execute'); 'execute');
} }
/** /**
* *
* Enter description here ... * Enter description here ...
* @param ccShowDays $showDay * @param ccShowDays $showDay
* @param DateTime $showStartDate user's local time * @param DateTime $showStartDate user's local time
@ -826,7 +826,7 @@ SQL;
} }
/** /**
* *
* Sets a single cc_show_instance table row * Sets a single cc_show_instance table row
* @param $showDay * @param $showDay
* @param $populateUntil * @param $populateUntil
@ -863,7 +863,7 @@ SQL;
} }
/** /**
* *
* Sets multiple cc_show_instances table rows * Sets multiple cc_show_instances table rows
* @param unknown_type $showDay * @param unknown_type $showDay
* @param unknown_type $populateUntil * @param unknown_type $populateUntil
@ -904,7 +904,7 @@ SQL;
/* /*
* Make sure start date is less than populate until date AND * Make sure start date is less than populate until date AND
* last show date is null OR start date is less than last show date * last show date is null OR start date is less than last show date
* *
* (NOTE: We cannot call getTimestamp() to compare the dates because of * (NOTE: We cannot call getTimestamp() to compare the dates because of
* a PHP 5.3.3 bug with DatePeriod objects - See CC-5159 for more details) * a PHP 5.3.3 bug with DatePeriod objects - See CC-5159 for more details)
*/ */
@ -964,8 +964,9 @@ SQL;
*/ */
if (isset($lastCreatedShow)) { if (isset($lastCreatedShow)) {
/* Set UTC to local time before setting the next repeat date. If we don't /* Set UTC to local time before setting the next repeat date. If we don't
* the next repeat date might be scheduled for the following day */ * the next repeat date might be scheduled for the following day
$lastCreatedShow->setTimezone(new DateTimeZone(Application_Model_Preference::GetTimezone())); * THIS MUST BE IN THE TIMEZONE THE SHOW WAS CREATED IN */
$lastCreatedShow->setTimezone(new DateTimeZone($timezone));
$nextDate = $lastCreatedShow->add($repeatInterval); $nextDate = $lastCreatedShow->add($repeatInterval);
$this->setNextRepeatingShowDate($nextDate->format("Y-m-d"), $day, $show_id); $this->setNextRepeatingShowDate($nextDate->format("Y-m-d"), $day, $show_id);
} }
@ -1064,10 +1065,10 @@ SQL;
} }
/** /**
* *
* i.e. last thursday of each month * i.e. last thursday of each month
* i.e. second monday of each month * i.e. second monday of each month
* *
* @param string $showStart * @param string $showStart
* @param string $timezone user's local timezone * @param string $timezone user's local timezone
*/ */
@ -1112,7 +1113,7 @@ SQL;
} }
/** /**
* *
* Enter description here ... * Enter description here ...
* @param $start user's local time * @param $start user's local time
*/ */
@ -1182,7 +1183,7 @@ SQL;
} }
/** /**
* *
* Create a DatePeriod object in the user's local time * Create a DatePeriod object in the user's local time
* It will get converted to UTC before the show instance gets created * It will get converted to UTC before the show instance gets created
*/ */
@ -1203,11 +1204,11 @@ SQL;
} }
/** /**
* *
* Attempts to retrieve the cc_show_instance belonging to a cc_show * Attempts to retrieve the cc_show_instance belonging to a cc_show
* that starts at $starts. We have to pass in the start * that starts at $starts. We have to pass in the start
* time in case the show is repeating * time in case the show is repeating
* *
* Returns the instance if one was found (one that is not a recording * Returns the instance if one was found (one that is not a recording
* and modified instance is false (has not been deleted)) * and modified instance is false (has not been deleted))
*/ */
@ -1250,7 +1251,7 @@ SQL;
} }
/** /**
* *
* Sets the fields for a cc_show table row * Sets the fields for a cc_show table row
* @param $ccShow * @param $ccShow
* @param $showData * @param $showData
@ -1285,7 +1286,7 @@ SQL;
} }
/** /**
* *
* Sets the fields for a cc_show_days table row * Sets the fields for a cc_show_days table row
* @param $showData * @param $showData
* @param $showId * @param $showId
@ -1367,7 +1368,7 @@ SQL;
} }
/** /**
* *
* Deletes all the cc_show_rebroadcast entries for a specific show * Deletes all the cc_show_rebroadcast entries for a specific show
* that is currently being edited. They will get recreated with * that is currently being edited. They will get recreated with
* the new show specs * the new show specs
@ -1378,7 +1379,7 @@ SQL;
} }
/** /**
* *
* Sets the fields for a cc_show_rebroadcast table row * Sets the fields for a cc_show_rebroadcast table row
* @param $showData * @param $showData
* @param $showId * @param $showId
@ -1417,7 +1418,7 @@ SQL;
} }
/** /**
* *
* Deletes all the cc_show_hosts entries for a specific show * Deletes all the cc_show_hosts entries for a specific show
* that is currently being edited. They will get recreated with * that is currently being edited. They will get recreated with
* the new show specs * the new show specs
@ -1428,7 +1429,7 @@ SQL;
} }
/** /**
* *
* Sets the fields for a cc_show_hosts table row * Sets the fields for a cc_show_hosts table row
* @param $showData * @param $showData
* @param $showId * @param $showId
@ -1446,10 +1447,10 @@ SQL;
} }
/** /**
* *
* Gets the date and time shows (particularly repeating shows) * Gets the date and time shows (particularly repeating shows)
* can be populated until. * can be populated until.
* *
* @return DateTime object * @return DateTime object
*/ */
private static function getPopulateShowUntilDateTIme() private static function getPopulateShowUntilDateTIme()
@ -1464,13 +1465,13 @@ SQL;
} }
/** /**
* *
* Enter description here ... * Enter description here ...
* @param DateTime $showStart user's local time * @param DateTime $showStart user's local time
* @param string $duration time interval (h)h:(m)m(:ss) * @param string $duration time interval (h)h:(m)m(:ss)
* @param string $timezone "Europe/Prague" * @param string $timezone "Europe/Prague"
* @param array $offset (days, hours, mins) used for rebroadcast shows * @param array $offset (days, hours, mins) used for rebroadcast shows
* *
* @return array of 2 DateTime objects, start/end time of the show in UTC * @return array of 2 DateTime objects, start/end time of the show in UTC
*/ */
private function createUTCStartEndDateTime($showStart, $duration, $offset=null) private function createUTCStartEndDateTime($showStart, $duration, $offset=null)
@ -1496,12 +1497,12 @@ SQL;
} }
/** /**
* *
* Show instances for repeating shows only get created up * Show instances for repeating shows only get created up
* until what is visible on the calendar. We need to set the * until what is visible on the calendar. We need to set the
* date for when the next repeating show instance should be created * date for when the next repeating show instance should be created
* as the user browses the calendar further. * as the user browses the calendar further.
* *
* @param $nextDate * @param $nextDate
* @param $showId * @param $showId
* @param $day * @param $day