CC-4668: Blocks/Playlists: Length includes deleted tracks

-fixed
This commit is contained in:
denise 2012-11-06 10:58:25 -05:00
parent e434af368f
commit 6ef646124e
3 changed files with 33 additions and 4 deletions

View File

@ -359,9 +359,26 @@ SQL;
Application_Model_RabbitMq::SendMessageToMediaMonitor("file_delete", $data);
}
// set file_exists falg to false
// set file_exists flag to false
$this->_file->setDbFileExists(false);
$this->_file->save();
// need to explicitly update any playlist's and block's length
// that contains the file getting deleted
$fileId = $this->_file->getDbId();
$plRows = CcPlaylistcontentsQuery::create()->filterByDbFileId()->find();
foreach ($plRows as $row) {
$pl = CcPlaylistQuery::create()->filterByDbId($row->getDbPlaylistId($fileId))->findOne();
$pl->setDbLength($pl->computeDbLength(Propel::getConnection(CcPlaylistPeer::DATABASE_NAME)));
$pl->save();
}
$blRows = CcBlockcontentsQuery::create()->filterByDbFileId($fileId)->find();
foreach ($blRows as $row) {
$bl = CcBlockQuery::create()->filterByDbId($row->getDbBlockId())->findOne();
$bl->setDbLength($bl->computeDbLength(Propel::getConnection(CcBlockPeer::DATABASE_NAME)));
$bl->save();
}
}
/**

View File

@ -86,8 +86,14 @@ class CcBlock extends BaseCcBlock {
*/
public function computeDbLength(PropelPDO $con)
{
$stmt = $con->prepare('SELECT SUM(cliplength) FROM "cc_blockcontents" WHERE cc_blockcontents.BLOCK_ID = :p1');
$stmt->bindValue(':p1', $this->getDbId());
$sql = <<<SQL
SELECT SUM(cliplength) FROM cc_blockcontents as bc
JOIN cc_files as f ON bc.file_id = f.id
WHERE BLOCK_ID = :b1
AND f.file_exists = true
SQL;
$stmt = $con->prepare($sql);
$stmt->bindValue(':b1', $this->getDbId());
$stmt->execute();
$length = $stmt->fetchColumn();

View File

@ -87,7 +87,13 @@ class CcPlaylist extends BaseCcPlaylist {
*/
public function computeDbLength(PropelPDO $con)
{
$stmt = $con->prepare('SELECT SUM(cliplength) FROM "cc_playlistcontents" WHERE cc_playlistcontents.PLAYLIST_ID = :p1');
$sql = <<<SQL
SELECT SUM(cliplength) FROM cc_playlistcontents as pc
JOIN cc_files as f ON pc.file_id = f.id
WHERE PLAYLIST_ID = :p1
AND f.file_exists = true
SQL;
$stmt = $con->prepare($sql);
$stmt->bindValue(':p1', $this->getDbId());
$stmt->execute();
$length = $stmt->fetchColumn();