diff --git a/feeds.module b/feeds.module index dd6264b..04bf60d 100644 --- a/feeds.module +++ b/feeds.module @@ -53,20 +53,19 @@ function feeds_cron() { ->execute(); // Find importers that need to be rescheduled. - if (!$importers = feeds_reschedule()) { - return; - } - - // @todo Maybe we should queue this somehow as well. This could be potentially - // very long. - $sources = db_query("SELECT feed_nid, id FROM {feeds_source} WHERE id IN (:ids)", array(':ids' => $importers)); + $importers = feeds_reschedule(); + if ($importers) { + // @todo Maybe we should queue this somehow as well. This could be potentially + // very long. + $sources = db_query("SELECT feed_nid, id FROM {feeds_source} WHERE id IN (:ids)", array(':ids' => $importers)); + + foreach ($sources as $source) { + feeds_source($source->id, $source->feed_nid)->schedule(); + } - foreach ($sources as $source) { - feeds_source($source->id, $source->feed_nid)->schedule(); + feeds_reschedule(FALSE); } - feeds_reschedule(FALSE); - // Sync the files in the cache directory with entries in the cache every now // and then. By default: every six hours. $last_check = variable_get('feeds_sync_cache_feeds_http_last_check'); diff --git a/tests/feeds_fetcher_http.test b/tests/feeds_fetcher_http.test index 5fc5239..1a7a6ab 100644 --- a/tests/feeds_fetcher_http.test +++ b/tests/feeds_fetcher_http.test @@ -262,6 +262,39 @@ class FeedsFileHTTPTestCase extends FeedsWebTestCase { } /** + * Tests if the cron task for cleaning up cached files are run one at a time. + */ + public function testCachedFilesCleanupQueue() { + $queue = DrupalQueue::get('feeds_sync_cache_feeds_http'); + + // First, make sure that a queue task is only ran every six hours. + variable_set('feeds_sync_cache_feeds_http_last_check', REQUEST_TIME); + + // Run cron without executing the queue tasks. + feeds_cron(); + + // Assert that no task was created for cleaning up the files. + $this->assertEqual(0, $queue->numberOfItems(), 'No task was created for the feeds_sync_cache_feeds_http queue.'); + + // Unset last check and run cron. + variable_del('feeds_sync_cache_feeds_http_last_check'); + feeds_cron(); + + // Assert that one task was created for cleaning up the files and that the + // variable for the last check was updated. + $this->assertEqual(1, $queue->numberOfItems(), 'One task was created for the feeds_sync_cache_feeds_http queue.'); + $this->assertEqual(REQUEST_TIME, variable_get('feeds_sync_cache_feeds_http_last_check')); + + // Unset last check and run cron again. + variable_del('feeds_sync_cache_feeds_http_last_check'); + feeds_cron(); + + // Assert that there still is one task. + $this->assertEqual(1, $queue->numberOfItems(), 'One task exists for the feeds_sync_cache_feeds_http queue.'); + $this->assertEqual(REQUEST_TIME, variable_get('feeds_sync_cache_feeds_http_last_check')); + } + + /** * Tests if a source is not refetched on a second import when the source did * not change. */