Merge branch '2.5.x' into cc-5709-airtime-analyzer

This commit is contained in:
Albert Santoni 2014-05-30 17:12:42 -04:00
commit 9f9c32aec3
2 changed files with 52 additions and 0 deletions

View File

@ -1118,6 +1118,41 @@ SQL;
return $real_streams;
}
/** Find out if a playlist contains any files that have been deleted from disk.
* This function relies on the "file_exists" column in the database being accurate and true,
* which it should.
* @return boolean true if there are missing files in this playlist, false otherwise.
*/
public function containsMissingFiles()
{
$playlistContents = $this->pl->getCcPlaylistcontentss("type = 0"); //type=0 is only files, not other types of media
//Slightly faster than the other Propel version below (this one does an INNER JOIN):
$missingFiles = CcFilesQuery::create()
->join("CcFiles.CcPlaylistcontents")
->where("CcPlaylistcontents.DbPlaylistId = ?", $this->pl->getDbId())
->where("CcFiles.DbFileExists = ?", 'false')
->find();
//Nicer Propel version but slightly slower because it generates a LEFT JOIN:
/*
$missingFiles = CcPlaylistcontentsQuery::create()
->filterByDbPlaylistId($this->pl->getDbId())
->useCcFilesQuery()
->filterByDbFileExists(false)
->endUse()
->find();
*/
if (!$missingFiles->isEmpty())
{
return true;
}
return false;
}
} // class Playlist
class PlaylistNotFoundException extends Exception {}

View File

@ -182,6 +182,22 @@ class Application_Model_Scheduler
}
}
}
private function validateMediaItems($mediaItems)
{
foreach ($mediaItems as $mediaItem)
{
$id = $mediaItem["id"];
if ($mediaItem["type"] === "playlist")
{
$playlist = new Application_Model_Playlist($id, $this->con);
if ($playlist->containsMissingFiles()) {
throw new Exception(_("Cannot schedule a playlist that contains missing files."));
}
}
}
return true;
}
/*
* @param $id
@ -951,6 +967,7 @@ class Application_Model_Scheduler
$this->con->beginTransaction();
try {
$this->validateMediaItems($mediaItems); //Check for missing files, etc.
$this->validateRequest($scheduleItems, true);
/*