diff --git a/airtime_mvc/application/services/SchedulerService.php b/airtime_mvc/application/services/SchedulerService.php index 7ab662c5c..c1dd6fc1f 100644 --- a/airtime_mvc/application/services/SchedulerService.php +++ b/airtime_mvc/application/services/SchedulerService.php @@ -248,22 +248,24 @@ class Application_Service_SchedulerService } } //foreach linked instance - $insert_sql = "INSERT INTO cc_schedule (starts, ends, ". - "clip_length, fade_in, fade_out, cue_in, cue_out, ". - "file_id, stream_id, instance_id, position) VALUES ". - implode($values, ","); + if (!empty($values)) { + $insert_sql = "INSERT INTO cc_schedule (starts, ends, ". + "clip_length, fade_in, fade_out, cue_in, cue_out, ". + "file_id, stream_id, instance_id, position) VALUES ". + implode($values, ","); - Application_Common_Database::prepareAndExecute( - $insert_sql, array(), Application_Common_Database::EXECUTE); + Application_Common_Database::prepareAndExecute( + $insert_sql, array(), Application_Common_Database::EXECUTE); - //update time_filled in cc_show_instances - $now = gmdate("Y-m-d H:i:s"); - $update_sql = "UPDATE cc_show_instances SET ". - "time_filled = '{$timeFilled}', ". - "last_scheduled = '{$now}' ". - "WHERE show_id = {$ccShow->getDbId()}"; - Application_Common_Database::prepareAndExecute( - $update_sql, array(), Application_Common_Database::EXECUTE); + //update time_filled in cc_show_instances + $now = gmdate("Y-m-d H:i:s"); + $update_sql = "UPDATE cc_show_instances SET ". + "time_filled = '{$timeFilled}', ". + "last_scheduled = '{$now}' ". + "WHERE show_id = {$ccShow->getDbId()}"; + Application_Common_Database::prepareAndExecute( + $update_sql, array(), Application_Common_Database::EXECUTE); + } } //if at least one linked instance has content } diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index 3efe45e0f..610449714 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -655,15 +655,16 @@ SQL; ->filterByDbDay($dayOfWeek) ->findOne(); - $lastShowStartDT->setTimeZone(new DateTimeZone( - $ccShowDay->getDbTimezone())); - $lastShowEndDT = Application_Service_CalendarService::addDeltas( - $lastShowStartDT, 1, 0); + if (isset($ccShowDay)) { + $lastShowStartDT->setTimeZone(new DateTimeZone( + $ccShowDay->getDbTimezone())); + $lastShowEndDT = Application_Service_CalendarService::addDeltas( + $lastShowStartDT, 1, 0); - $ccShowDay - ->setDbLastShow($lastShowEndDT->format("Y-m-d")) - ->save(); - + $ccShowDay + ->setDbLastShow($lastShowEndDT->format("Y-m-d")) + ->save(); + } } //remove the old repeating deleted instances. @@ -872,6 +873,7 @@ SQL; private function createWeeklyRepeatInstances($showDay, $populateUntil, $repeatType, $repeatInterval, $daysAdded=null) { + $show_id = $showDay->getDbShowId(); $first_show = $showDay->getDbFirstShow(); //non-UTC $last_show = $showDay->getDbLastShow(); //non-UTC @@ -894,10 +896,8 @@ SQL; $utcLastShowDateTime = $last_show ? Application_Common_DateHelper::ConvertToUtcDateTime($last_show, $timezone) : null; - $utcStartDateTime = new DateTime("now"); $previousDate = clone $start; foreach ($datePeriod as $date) { - list($utcStartDateTime, $utcEndDateTime) = $this->createUTCStartEndDateTime( $date, $duration); /* @@ -954,12 +954,19 @@ SQL; $previousDate = clone $date; } - /* 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 + /* We need to set the next populate date for repeat shows so when a user + * moves forward in the calendar we know when to start generating new + * show instances. + * If $utcStartDateTime is not set then we know zero new shows were + * created and we shouldn't update the next populate date. */ - $utcStartDateTime->setTimezone(new DateTimeZone(Application_Model_Preference::GetTimezone())); - $nextDate = $utcStartDateTime->add($repeatInterval); - $this->setNextRepeatingShowDate($nextDate->format("Y-m-d"), $day, $show_id); + if (isset($utcStartDateTime)) { + /* 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 */ + $utcStartDateTime->setTimezone(new DateTimeZone(Application_Model_Preference::GetTimezone())); + $nextDate = $utcStartDateTime->add($repeatInterval); + $this->setNextRepeatingShowDate($nextDate->format("Y-m-d"), $day, $show_id); + } } private function createMonthlyRepeatInstances($showDay, $populateUntil)