From 52f0d5a13be102e5da8cd393d9092dcb551c70f6 Mon Sep 17 00:00:00 2001 From: drigato Date: Fri, 22 Nov 2013 09:39:19 -0500 Subject: [PATCH] CC-5570: Tracks get scheduled ahead of their show start time --- airtime_mvc/application/models/Scheduler.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/airtime_mvc/application/models/Scheduler.php b/airtime_mvc/application/models/Scheduler.php index 9cbb2f965..8bb477bc5 100644 --- a/airtime_mvc/application/models/Scheduler.php +++ b/airtime_mvc/application/models/Scheduler.php @@ -617,6 +617,23 @@ class Application_Model_Scheduler $linkedItemEnds = Application_Common_Database::prepareAndExecute( $linkedItem_sql, array(), Application_Common_Database::COLUMN); + if (!$linkedItemEnds) { + //With dynamic smart blocks there may be different number of items in + //each show. In case the position does not exist we need to select + //the end time of the last position + $maxPos_sql = "SELECT max(position) from cc_schedule ". + "WHERE instance_id = {$instanceId}"; + $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); + } + $nextStartDT = $this->findNextStartTime( new DateTime($linkedItemEnds, new DateTimeZone("UTC")), $instanceId);