This commit is contained in:
Duncan Sommerville 2014-10-28 13:30:16 -04:00
commit 2f96885d65
1 changed files with 28 additions and 19 deletions

View File

@ -1291,27 +1291,36 @@ SQL;
return $updateIsScheduled;
}
/**
*
* Updates the is_scheduled flag to false for tracks that are no longer
* scheduled in the future. We do this by checking the difference between
* all files scheduled in the future and all files with is_scheduled = true.
* The difference of the two result sets is what we need to update.
*/
public static function updatePastFilesIsScheduled()
{
/* Set the is_scheduled flag to false where it was true in the
* past, and where tracks are not scheduled in the future and do
* not belong to a show that has not ended yet. We need to check
* for show end times in case a track is overbooked, which would
* indicate it is still scheduled in the future
*/
$sql = <<<SQL
UPDATE cc_files SET is_scheduled = false
WHERE is_scheduled = true
AND id NOT IN (
SELECT s.file_id FROM cc_schedule AS s
LEFT JOIN cc_show_instances AS i
ON s.instance_id = i.id
WHERE s.ends > now() at time zone 'UTC'
AND i.ends > now() at time zone 'UTC'
)
SQL;
Application_Common_Database::prepareAndExecute($sql, array(),
Application_Common_Database::EXECUTE);
$futureScheduledFilesSelectCriteria = new Criteria();
$futureScheduledFilesSelectCriteria->addSelectColumn(CcSchedulePeer::FILE_ID);
$futureScheduledFilesSelectCriteria->setDistinct();
$futureScheduledFilesSelectCriteria->add(CcSchedulePeer::ENDS, gmdate("Y-m-d H:i:s"), Criteria::GREATER_THAN);
$stmt = CcSchedulePeer::doSelectStmt($futureScheduledFilesSelectCriteria);
$filesScheduledInFuture = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
$filesCurrentlySetWithIsScheduledSelectCriteria = new Criteria();
$filesCurrentlySetWithIsScheduledSelectCriteria->addSelectColumn(CcFilesPeer::ID);
$filesCurrentlySetWithIsScheduledSelectCriteria->add(CcFilesPeer::IS_SCHEDULED, true);
$stmt = CcFilesPeer::doSelectStmt($filesCurrentlySetWithIsScheduledSelectCriteria);
$filesCurrentlySetWithIsScheduled = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
$diff = array_diff($filesCurrentlySetWithIsScheduled, $filesScheduledInFuture);
$con = Propel::getConnection(CcFilesPeer::DATABASE_NAME);
$selectCriteria = new Criteria();
$selectCriteria->add(CcFilesPeer::ID, $diff, Criteria::IN);
$updateCriteria = new Criteria();
$updateCriteria->add(CcFilesPeer::IS_SCHEDULED, false);
BasePeer::doUpdate($selectCriteria, $updateCriteria, $con);
}
}