From eff7cd2f072de53fd0452deb69e4107bc3c7cb81 Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Fri, 27 Nov 2015 16:48:44 -0500 Subject: [PATCH] Fix bug in podcast download --- .../application/common/TaskManager.php | 22 ++++++------------- .../services/PodcastEpisodeService.php | 4 ++-- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/airtime_mvc/application/common/TaskManager.php b/airtime_mvc/application/common/TaskManager.php index dbb7ccb60..126060a28 100644 --- a/airtime_mvc/application/common/TaskManager.php +++ b/airtime_mvc/application/common/TaskManager.php @@ -329,8 +329,6 @@ class BandwidthLimitTask implements AirtimeTask { /** * Run the task - * - * @return void */ public function run() { Application_Model_Preference::resetStationPodcastDownloadCounter(); @@ -362,27 +360,21 @@ class TaskFactory { * * @return array all classes implementing the AirtimeTask interface */ - private static function _getTaskClasses() { + public static function getTasks() { return array_filter(get_declared_classes(), array(__CLASS__, "_isTask")); } /** - * @return array - */ - public static function getTasks() { - return self::_getTaskClasses(); - } - - /** - * Get an AirtimeTask based on a task type + * Get an AirtimeTask based on class name * - * @param $task string the task type; uses AirtimeTask constants as an ENUM + * @param $task string name of the class implementing AirtimeTask to construct * - * @return AirtimeTask|null return a task of the given type or null if no corresponding - * task exists or is implemented + * @return AirtimeTask|null return a task of the given type or null if no corresponding task exists */ public static function getTask($task) { - return new $task(); + // Try to get a valid class name from the given string + if (!class_exists($task)) $task = str_replace(' ', '', ucwords($task)) . "Task"; + return class_exists($task) ? new $task() : null; } } diff --git a/airtime_mvc/application/services/PodcastEpisodeService.php b/airtime_mvc/application/services/PodcastEpisodeService.php index 60e9b3879..1ceda4829 100644 --- a/airtime_mvc/application/services/PodcastEpisodeService.php +++ b/airtime_mvc/application/services/PodcastEpisodeService.php @@ -145,7 +145,7 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir 'id' => $id, 'url' => $url, 'callback_url' => $stationUrl . 'rest/media', - 'api_key' => $apiKey = $CC_CONFIG["apiKey"][0], + 'api_key' => $CC_CONFIG["apiKey"][0], ); $task = $this->_executeTask(static::$_CELERY_TASKS[self::DOWNLOAD], $data); // Get the created ThirdPartyTaskReference and set the episode ID so @@ -251,7 +251,7 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir public static function getStuckPendingImports() { $timeout = gmdate(DEFAULT_TIMESTAMP_FORMAT, (microtime(true) - self::PENDING_EPISODE_TIMEOUT_SECONDS)); $episodes = PodcastEpisodesQuery::create() - ->filterByDbFileId(null, Criteria::ISNULL) + ->filterByDbFileId() ->find(); $stuckImports = array(); foreach ($episodes as $episode) {