CC-3034 Record/Rebroadcast Shows have time problems
fixing some UTC to non UTC comparisons, adding offsets properly to create a rebroadcast show's start/end time.
This commit is contained in:
parent
fe5191eac1
commit
61d8fa7baa
|
@ -1030,7 +1030,9 @@ class Application_Model_Show {
|
|||
$sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id={$show_id}";
|
||||
$rebroadcasts = $CC_DBC->GetAll($sql);
|
||||
|
||||
self::createRebroadcastInstances($rebroadcasts, $currentUtcTimestamp, $show_id, $show_instance_id, $utcStartDateTime, $duration);
|
||||
Logging::log('$start time of non repeating record '.$start);
|
||||
|
||||
self::createRebroadcastInstances($rebroadcasts, $currentUtcTimestamp, $show_id, $show_instance_id, $start, $duration, $timezone);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1042,9 +1044,9 @@ class Application_Model_Show {
|
|||
* @param array $p_showRow
|
||||
* A row from cc_show_days table
|
||||
* @param DateTime $p_dateTime
|
||||
* DateTime object in UTC time.
|
||||
* DateTime object in UTC time. "shows_populated_until" date YY-mm-dd in cc_pref
|
||||
* @param string $p_interval
|
||||
* Period of time between repeating shows
|
||||
* Period of time between repeating shows (in php DateInterval notation 'P7D')
|
||||
*/
|
||||
private static function populateRepeatingShow($p_showRow, $p_dateTime, $p_interval)
|
||||
{
|
||||
|
@ -1060,6 +1062,8 @@ class Application_Model_Show {
|
|||
$record = $p_showRow["record"];
|
||||
$timezone = $p_showRow["timezone"];
|
||||
|
||||
$date = new Application_Model_DateHelper();
|
||||
$currentUtcTimestamp = $date->getUtcTimestamp();
|
||||
|
||||
if(isset($next_pop_date)) {
|
||||
$start = $next_pop_date." ".$start_time;
|
||||
|
@ -1068,17 +1072,16 @@ class Application_Model_Show {
|
|||
}
|
||||
|
||||
$utcStartDateTime = Application_Model_DateHelper::ConvertToUtcDateTime($start, $timezone);
|
||||
//convert $last_show into a UTC DateTime object, or null if there is no last show.
|
||||
$utcLastShowDateTime = $last_show ? Application_Model_DateHelper::ConvertToUtcDateTime($last_show, $timezone) : null;
|
||||
|
||||
$sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id={$show_id}";
|
||||
$rebroadcasts = $CC_DBC->GetAll($sql);
|
||||
|
||||
$show = new Application_Model_Show($show_id);
|
||||
|
||||
$date = new Application_Model_DateHelper();
|
||||
$currentUtcTimestamp = $date->getUtcTimestamp();
|
||||
|
||||
while($utcStartDateTime->getTimestamp()
|
||||
<= $p_dateTime->getTimestamp() &&
|
||||
($utcStartDateTime->getTimestamp() < strtotime($last_show) || is_null($last_show))) {
|
||||
while($utcStartDateTime->getTimestamp() <= $p_dateTime->getTimestamp()
|
||||
&& (is_null($utcLastShowDateTime) || $utcStartDateTime->getTimestamp() < $utcLastShowDateTime->getTimestamp())){
|
||||
|
||||
$utcStart = $utcStartDateTime->format("Y-m-d H:i:s");
|
||||
$sql = "SELECT timestamp '{$utcStart}' + interval '{$duration}'";
|
||||
|
@ -1113,7 +1116,7 @@ class Application_Model_Show {
|
|||
$showInstance->correctScheduleStartTimes();
|
||||
}
|
||||
|
||||
self::createRebroadcastInstances($rebroadcasts, $currentUtcTimestamp, $show_id, $show_instance_id, $utcStartDateTime, $duration);
|
||||
self::createRebroadcastInstances($rebroadcasts, $currentUtcTimestamp, $show_id, $show_instance_id, $start, $duration, $timezone);
|
||||
|
||||
$dt = new DateTime($start, new DateTimeZone($timezone));
|
||||
$dt->add(new DateInterval($p_interval));
|
||||
|
@ -1127,23 +1130,49 @@ class Application_Model_Show {
|
|||
Application_Model_Show::setNextPop($start, $show_id, $day);
|
||||
}
|
||||
|
||||
private static function createRebroadcastInstances($p_rebroadcasts, $p_currentUtcTimestamp, $p_showId, $p_showInstanceId, $p_utcStartDateTime, $p_duration){
|
||||
/* Create rebroadcast instances for a created show marked for recording
|
||||
*
|
||||
* @param $p_rebroadcasts rows gotten from the db table cc_show_rebroadcasts, tells airtime when to schedule the rebroadcasts.
|
||||
* @param $p_currentUtcTimestamp a timestring in format "Y-m-d H:i:s", current UTC time.
|
||||
* @param $p_showId int of the show it belongs to (from cc_show)
|
||||
* @param $p_showInstanceId the instance id of the created recorded show instance
|
||||
* (from cc_show_instances), used to associate rebroadcasts to this show.
|
||||
* @param $p_startTime a timestring in format "Y-m-d H:i:s" in the timezone, not UTC of the rebroadcasts' parent recorded show.
|
||||
* @param $p_duration duration of the show in format 1:0
|
||||
* @param $p_timezone string of user's timezone "Europe/Prague"
|
||||
*
|
||||
*/
|
||||
private static function createRebroadcastInstances($p_rebroadcasts, $p_currentUtcTimestamp, $p_showId, $p_showInstanceId, $p_startTime, $p_duration, $p_timezone=null){
|
||||
global $CC_DBC;
|
||||
|
||||
foreach($p_rebroadcasts as $rebroadcast) {
|
||||
$timeinfo = $p_utcStartDateTime->format("Y-m-d H:i:s");
|
||||
Logging::log('Count of rebroadcasts '. count($p_rebroadcasts));
|
||||
|
||||
$sql = "SELECT timestamp '{$timeinfo}' + interval '{$rebroadcast["day_offset"]}' + interval '{$rebroadcast["start_time"]}'";
|
||||
foreach($p_rebroadcasts as $rebroadcast) {
|
||||
|
||||
//use only the date part of the show start time stamp for the offsets to work properly.
|
||||
$sql = "SELECT date '{$p_startTime}' + interval '{$rebroadcast["day_offset"]}' + interval '{$rebroadcast["start_time"]}'";
|
||||
$rebroadcast_start_time = $CC_DBC->GetOne($sql);
|
||||
Logging::log('rebroadcast start '.$rebroadcast_start_time);
|
||||
|
||||
$sql = "SELECT timestamp '{$rebroadcast_start_time}' + interval '{$p_duration}'";
|
||||
$rebroadcast_end_time = $CC_DBC->GetOne($sql);
|
||||
Logging::log('rebroadcast end '.$rebroadcast_end_time);
|
||||
|
||||
//convert to UTC, after we have used the defined offsets to calculate rebroadcasts.
|
||||
$utc_rebroadcast_start_time = Application_Model_DateHelper::ConvertToUtcDateTime($rebroadcast_start_time, $p_timezone);
|
||||
$utc_rebroadcast_end_time = Application_Model_DateHelper::ConvertToUtcDateTime($rebroadcast_end_time, $p_timezone);
|
||||
|
||||
Logging::log('UTC rebroadcast start '.$utc_rebroadcast_start_time->format("Y-m-d H:i:s"));
|
||||
Logging::log('UTC rebroadcast end '.$utc_rebroadcast_end_time->format("Y-m-d H:i:s"));
|
||||
Logging::log('Current UTC timestamp '.$p_currentUtcTimestamp);
|
||||
|
||||
if ($utc_rebroadcast_start_time->format("Y-m-d H:i:s") > $p_currentUtcTimestamp){
|
||||
Logging::log('Creating rebroadcast show starting at UTC '.$utc_rebroadcast_start_time->format("Y-m-d H:i:s"));
|
||||
|
||||
if ($rebroadcast_start_time > $p_currentUtcTimestamp){
|
||||
$newRebroadcastInstance = new CcShowInstances();
|
||||
$newRebroadcastInstance->setDbShowId($p_showId);
|
||||
$newRebroadcastInstance->setDbStarts($rebroadcast_start_time);
|
||||
$newRebroadcastInstance->setDbEnds($rebroadcast_end_time);
|
||||
$newRebroadcastInstance->setDbStarts($utc_rebroadcast_start_time->format("Y-m-d H:i:s"));
|
||||
$newRebroadcastInstance->setDbEnds($utc_rebroadcast_end_time->format("Y-m-d H:i:s"));
|
||||
$newRebroadcastInstance->setDbRecord(0);
|
||||
$newRebroadcastInstance->setDbRebroadcast(1);
|
||||
$newRebroadcastInstance->setDbOriginalShow($p_showInstanceId);
|
||||
|
|
Loading…
Reference in New Issue