diff --git a/airtime_mvc/application/models/Scheduler.php b/airtime_mvc/application/models/Scheduler.php index 8bb477bc5..9cb79927c 100644 --- a/airtime_mvc/application/models/Scheduler.php +++ b/airtime_mvc/application/models/Scheduler.php @@ -626,19 +626,32 @@ class Application_Model_Scheduler $pos = Application_Common_Database::prepareAndExecute( $maxPos_sql, array(), Application_Common_Database::COLUMN); - $linkedItem_sql = "SELECT ends FROM cc_schedule ". - "WHERE instance_id = {$instanceId} ". - "AND position = {$pos} ". - "AND playout_status != -1"; - $linkedItemEnds = Application_Common_Database::prepareAndExecute( - $linkedItem_sql, array(), Application_Common_Database::COLUMN); + //show instance has no scheduled tracks + if (empty($pos)) { + $pos = 0; + $nextStartDT = new DateTime($instance["starts"], new DateTimeZone("UTC")); + } else { + + $linkedItem_sql = "SELECT ends FROM cc_schedule ". + "WHERE instance_id = {$instanceId} ". + "AND position = {$pos} ". + "AND playout_status != -1"; + $linkedItemEnds = Application_Common_Database::prepareAndExecute( + $linkedItem_sql, array(), Application_Common_Database::COLUMN); + + $nextStartDT = $this->findNextStartTime( + new DateTime($linkedItemEnds, new DateTimeZone("UTC")), + $instanceId); + } + } else { + $nextStartDT = $this->findNextStartTime( + new DateTime($linkedItemEnds, new DateTimeZone("UTC")), + $instanceId); + + $pos++; } - $nextStartDT = $this->findNextStartTime( - new DateTime($linkedItemEnds, new DateTimeZone("UTC")), - $instanceId); - - $pos++; + //$pos++; } //selected empty row to add after else { @@ -722,6 +735,13 @@ class Application_Model_Scheduler $sched = Application_Common_Database::prepareAndExecute( $movedItem_sql, array(), Application_Common_Database::SINGLE); } + /* If we don't find a schedule item it means the linked + * shows have a different amount of items (dyanmic block) + * and we should skip the item move for this show instance + */ + if (!$sched) { + continue; + } $excludeIds[] = intval($sched["id"]); $file["cliplength"] = $sched["clip_length"]; @@ -1160,6 +1180,7 @@ class Application_Model_Scheduler foreach ($instances as $instance) { $instance->updateScheduleStatus($this->con); + $instance->correctSchedulePositions(); } //update the last scheduled timestamp. diff --git a/airtime_mvc/application/models/airtime/CcShowInstances.php b/airtime_mvc/application/models/airtime/CcShowInstances.php index 6fdaaf8a2..e7dace7b1 100644 --- a/airtime_mvc/application/models/airtime/CcShowInstances.php +++ b/airtime_mvc/application/models/airtime/CcShowInstances.php @@ -138,6 +138,29 @@ class CcShowInstances extends BaseCcShowInstances { $this->setDbLastScheduled(gmdate("Y-m-d H:i:s")); $this->save($con); } + + /** + * + * This function resets the cc_schedule table's position numbers so that + * tracks for each cc_show_instances start at position 1 + * + * The position numbers can become out of sync when the user deletes items + * from linekd shows filled with dyanmic smart blocks, where each instance + * has a different amount of scheduled items + */ + public function correctSchedulePositions() + { + $schedule = CcScheduleQuery::create() + ->filterByDbInstanceId($this->id) + ->orderByDbStarts() + ->find(); + + $pos = 0; + foreach ($schedule as $item) { + $item->setDbPosition($pos)->save(); + $pos++; + } + } /** * Computes the value of the aggregate column time_filled