diff --git a/airtime_mvc/application/models/Playlist.php b/airtime_mvc/application/models/Playlist.php index 7eaad0a64..7a7573d2a 100644 --- a/airtime_mvc/application/models/Playlist.php +++ b/airtime_mvc/application/models/Playlist.php @@ -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 {} diff --git a/airtime_mvc/application/models/Scheduler.php b/airtime_mvc/application/models/Scheduler.php index 85e8f6f24..4aa1182c6 100644 --- a/airtime_mvc/application/models/Scheduler.php +++ b/airtime_mvc/application/models/Scheduler.php @@ -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); /*