8.5.x aggregator.module aggregator_cron()
8.0.x aggregator.module aggregator_cron()
8.1.x aggregator.module aggregator_cron()
8.2.x aggregator.module aggregator_cron()
8.3.x aggregator.module aggregator_cron()
8.4.x aggregator.module aggregator_cron()
8.6.x aggregator.module aggregator_cron()
4.6.x aggregator.module aggregator_cron()
4.7.x aggregator.module aggregator_cron()
5.x aggregator.module aggregator_cron()
6.x aggregator.module aggregator_cron()
7.x aggregator.module aggregator_cron()

Implements hook_cron().

Queues news feeds for updates once their refresh interval has elapsed.

File

modules/aggregator/aggregator.module, line 311
Used to aggregate syndicated content (RSS, RDF, and Atom).

Code

function aggregator_cron() {
  $result = db_query('SELECT * FROM {aggregator_feed} WHERE queued = 0 AND checked + refresh < :time AND refresh <> :never', array(
    ':time' => REQUEST_TIME,
    ':never' => AGGREGATOR_CLEAR_NEVER,
  ));
  $queue = DrupalQueue::get('aggregator_feeds');
  foreach ($result as $feed) {
    if ($queue
      ->createItem($feed)) {

      // Add timestamp to avoid queueing item more than once.
      db_update('aggregator_feed')
        ->fields(array(
        'queued' => REQUEST_TIME,
      ))
        ->condition('fid', $feed->fid)
        ->execute();
    }
  }

  // Remove queued timestamp after 6 hours assuming the update has failed.
  db_update('aggregator_feed')
    ->fields(array(
    'queued' => 0,
  ))
    ->condition('queued', REQUEST_TIME - 3600 * 6, '<')
    ->execute();
}