From 7d1acab7b614f3c044b81739e92ab03908f7e12e Mon Sep 17 00:00:00 2001 From: Robbt Date: Mon, 18 Feb 2019 18:17:00 -0500 Subject: [PATCH] fixed autoloading playlist to avoid errors when trying to schedule empty playlist --- .../common/AutoPlaylistManager.php | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/airtime_mvc/application/common/AutoPlaylistManager.php b/airtime_mvc/application/common/AutoPlaylistManager.php index 7e052087e..c87efc095 100644 --- a/airtime_mvc/application/common/AutoPlaylistManager.php +++ b/airtime_mvc/application/common/AutoPlaylistManager.php @@ -13,7 +13,6 @@ class AutoPlaylistManager { * @return bool true if $_AUTOPLAYLIST_POLL_INTERVAL_SECONDS has passed since the last check */ public static function hasAutoPlaylistPollIntervalPassed() { - Logging::info("Checking autoplaylist poll"); $lastPolled = Application_Model_Preference::getAutoPlaylistPollLock(); return empty($lastPolled) || (microtime(true) > $lastPolled + self::$_AUTOPLAYLIST_POLL_INTERVAL_SECONDS); } @@ -23,7 +22,6 @@ class AutoPlaylistManager { * */ public static function buildAutoPlaylist() { - //Logging::info("Checking to run Auto Playlist"); $autoPlaylists = static::_upcomingAutoPlaylistShows(); foreach ($autoPlaylists as $autoplaylist) { // creates a ShowInstance object to build the playlist in from the ShowInstancesQuery Object @@ -40,11 +38,14 @@ class AutoPlaylistManager { // otherwise we continue to go through adding playlists, including the intro and outro if enabled $full = false; $repeatuntilfull = $playlistrepeat->getAutoPlaylistRepeat(); + $tempPercentScheduled = 0; while(!$full) { $si = new Application_Model_ShowInstance($autoplaylist->getDbId()); - $si->addPlaylistToShow($playlistid, false); + // we do not want to try to schedule an empty playlist + if ($playlistid != null) { + $si->addPlaylistToShow($playlistid, false); + } $ps = $si->getPercentScheduled(); - //Logging::info($ps); if ($introplaylistid != null) { //Logging::info('adding intro'); $si->addPlaylistToShowStart($introplaylistid, false); @@ -60,10 +61,19 @@ class AutoPlaylistManager { elseif (!$repeatuntilfull) { break; } - + // we want to avoid an infinite loop if all of the playlists are null + if ($playlistid == null && $introplaylistid == null && $outroplaylistid == null) { + break; + } + // another possible issue would be if the show isn't increasing in length each loop + // ie if all of the playlists being added are zero lengths this could cause an infinite loop + if ($tempPercentScheduled == $ps) { + break; + } + //now reset it to zero + $tempPercentScheduled = $ps; } $si->setAutoPlaylistBuilt(true); - } Application_Model_Preference::setAutoPlaylistPollLock(microtime(true)); }