CC-5904: New linked show instances may get an old copy of the schedule

This commit is contained in:
drigato 2014-08-18 18:10:45 -04:00
parent 62f8a65573
commit b9ecd00d33
2 changed files with 59 additions and 29 deletions

View File

@ -288,7 +288,26 @@ class CcShow extends BaseCcShow {
} }
return $instanceIds; return $instanceIds;
} }
/*
* Returns all show instances ordered by 'starts' column in desc order.
*/
public function getInstanceIdsSortedByMostRecentStartTime()
{
$instances = CcShowInstancesQuery::create()
->filterByCcShow($this)
->filterByDbModifiedInstance(false)
->orderByDbStarts(Criteria::DESC)
->find();
$instanceIdsDescOrder = array();
foreach ($instances as $instance) {
$instanceIdsDescOrder[] = $instance->getDbId();
}
return $instanceIdsDescOrder;
}
//what is this??
public function getOtherInstances($instanceId) public function getOtherInstances($instanceId)
{ {
return CcShowInstancesQuery::create() return CcShowInstancesQuery::create()

View File

@ -152,15 +152,25 @@ class Application_Service_SchedulerService
public static function fillNewLinkedInstances($ccShow) public static function fillNewLinkedInstances($ccShow)
{ {
/* First check if any linked instances have content /* In order to get the linked show's schedule we need to retrieve
* If all instances are empty then we don't need to fill * every instance of the show, even if they are in the past in case
* any other instances with content * no new instances were generated past the 'shows_populated_until'
* date in cc_pref - CC-5898
*
* We retrieve the instances ids sorted by desc start date to ensure
* we always use the most up to date schedule when filling the new
* show instances with content
*/ */
$instanceIds = $ccShow->getInstanceIds();
$instanceIds = $ccShow->getInstanceIdsSortedByMostRecentStartTime();
if (count($instanceIds) == 0) { if (count($instanceIds) == 0) {
return; return;
} }
/* First check if any linked instances have content
* If all instances are empty then we don't need to fill
* any other instances with content
*/
$doesAnyShowInstanceHaveContent = false; $doesAnyShowInstanceHaveContent = false;
foreach ($instanceIds as $instanceId) foreach ($instanceIds as $instanceId)
{ {
@ -181,29 +191,31 @@ class Application_Service_SchedulerService
return; return;
} }
/* Find the show contents of just one of the instances. It doesn't /* Find the show contents of just one of the instances. Because we
* matter which instance we use since all the content is the same * sorted the instances by desc order, we are using the most recent
*/ * instance, which will have the most up to date schedule.
$ccSchedule = $ccSchedules[0]; */
$showStamp_sql = "SELECT * FROM cc_schedule ". $ccSchedule = $ccSchedules[0];
"WHERE instance_id = {$ccSchedule["instance_id"]} ". $showStamp_sql = "SELECT * FROM cc_schedule ".
"ORDER BY starts"; "WHERE instance_id = {$ccSchedule["instance_id"]} ".
$showStamp = Application_Common_Database::prepareAndExecute( "ORDER BY starts";
$showStamp_sql); $showStamp = Application_Common_Database::prepareAndExecute(
$showStamp_sql);
//get time_filled so we can update cc_show_instances Logging::info(count($showStamp));
$timeFilled_sql = "SELECT time_filled FROM cc_show_instances ". Logging::info($showStamp[0]);
"WHERE id = {$ccSchedule["instance_id"]}"; //get time_filled so we can update cc_show_instances
$timeFilled = Application_Common_Database::prepareAndExecute( $timeFilled_sql = "SELECT time_filled FROM cc_show_instances ".
$timeFilled_sql, array(), Application_Common_Database::COLUMN); "WHERE id = {$ccSchedule["instance_id"]}";
$timeFilled = Application_Common_Database::prepareAndExecute(
//need to find out which linked instances are empty $timeFilled_sql, array(), Application_Common_Database::COLUMN);
$values = array();
$futureInstanceIds = $ccShow->getFutureInstanceIds(); //need to find out which linked instances are empty
$con = Propel::getConnection(); $values = array();
try { $futureInstanceIds = $ccShow->getFutureInstanceIds();
$con->beginTransaction(); $con = Propel::getConnection();
foreach ($instanceIds as $id) try {
$con->beginTransaction();
foreach ($futureInstanceIds as $id)
{ {
$instanceSched_sql = "SELECT * FROM cc_schedule ". $instanceSched_sql = "SELECT * FROM cc_schedule ".
"WHERE instance_id = {$id} ". "WHERE instance_id = {$id} ".
@ -217,7 +229,7 @@ class Application_Service_SchedulerService
* (The show stamp is taken from the first show instance's content) * (The show stamp is taken from the first show instance's content)
*/ */
if (count($ccSchedules) < 1 || if (count($ccSchedules) < 1 ||
self::replaceInstanceContentCheck($ccSchedules, $showStamp)) self::replaceInstanceContentCheck($ccSchedules, $showStamp, $id))
{ {
$instanceStart_sql = "SELECT starts FROM cc_show_instances ". $instanceStart_sql = "SELECT starts FROM cc_show_instances ".
@ -264,7 +276,6 @@ class Application_Service_SchedulerService
"clip_length, fade_in, fade_out, cue_in, cue_out, ". "clip_length, fade_in, fade_out, cue_in, cue_out, ".
"file_id, stream_id, instance_id, position) VALUES ". "file_id, stream_id, instance_id, position) VALUES ".
implode($values, ","); implode($values, ",");
Application_Common_Database::prepareAndExecute( Application_Common_Database::prepareAndExecute(
$insert_sql, array(), Application_Common_Database::EXECUTE); $insert_sql, array(), Application_Common_Database::EXECUTE);
} }