function aggregator_refresh

Checks a news feed for new items.

Parameters

$feed: An object describing the feed to be refreshed.

5 calls to aggregator_refresh()
aggregator_admin_refresh_feed in drupal/core/modules/aggregator/aggregator.admin.inc
Page callback: Refreshes a feed, then redirects to the overview page.
FeedParserTest::testAtomSample in drupal/core/modules/aggregator/lib/Drupal/aggregator/Tests/FeedParserTest.php
Test a feed that uses the Atom format.
FeedParserTest::testHtmlEntitiesSample in drupal/core/modules/aggregator/lib/Drupal/aggregator/Tests/FeedParserTest.php
Tests a feed that uses HTML entities in item titles.
FeedParserTest::testRSS091Sample in drupal/core/modules/aggregator/lib/Drupal/aggregator/Tests/FeedParserTest.php
Test a feed that uses the RSS 0.91 format.
UpdateFeedItemTest::testUpdateFeedItem in drupal/core/modules/aggregator/lib/Drupal/aggregator/Tests/UpdateFeedItemTest.php
Test running "update items" from the 'admin/config/services/aggregator' page.
2 string references to 'aggregator_refresh'
aggregator_queue_info in drupal/core/modules/aggregator/aggregator.module
Implements hook_queue_info().
hook_queue_info in drupal/core/modules/system/system.api.php
Declare queues holding items that need to be run periodically.

File

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

Code

function aggregator_refresh($feed) {

  // Store feed URL to track changes.
  $feed_url = $feed->url;
  list($fetcher, $parser, $processors) = _aggregator_get_variables();

  // Fetch the feed.
  $fetcher_manager = new FetcherManager();
  try {
    $success = $fetcher_manager
      ->createInstance($fetcher)
      ->fetch($feed);
  } catch (PluginException $e) {
    $success = FALSE;
  }

  // We store the hash of feed data in the database. When refreshing a
  // feed we compare stored hash and new hash calculated from downloaded
  // data. If both are equal we say that feed is not updated.
  $hash = hash('sha256', $feed->source_string);
  if ($success && $feed->hash != $hash) {

    // Parse the feed.
    if (module_invoke($parser, 'aggregator_parse', $feed)) {

      // Update feed with parsed data.
      db_merge('aggregator_feed')
        ->key(array(
        'fid' => $feed->fid,
      ))
        ->fields(array(
        'url' => $feed->url,
        'link' => empty($feed->link) ? $feed->url : $feed->link,
        'description' => empty($feed->description) ? '' : $feed->description,
        'image' => empty($feed->image) ? '' : $feed->image,
        'hash' => $hash,
        'etag' => empty($feed->etag) ? '' : $feed->etag,
        'modified' => empty($feed->modified) ? 0 : $feed->modified,
      ))
        ->execute();

      // Log if feed URL has changed.
      if ($feed->url != $feed_url) {
        watchdog('aggregator', 'Updated URL for feed %title to %url.', array(
          '%title' => $feed->title,
          '%url' => $feed->url,
        ));
      }
      watchdog('aggregator', 'There is new syndicated content from %site.', array(
        '%site' => $feed->title,
      ));
      drupal_set_message(t('There is new syndicated content from %site.', array(
        '%site' => $feed->title,
      )));

      // If there are items on the feed, let all enabled processors do their work on it.
      if (@count($feed->items)) {
        foreach ($processors as $processor) {
          module_invoke($processor, 'aggregator_process', $feed);
        }
      }
    }
  }
  else {
    drupal_set_message(t('There is no new syndicated content from %site.', array(
      '%site' => $feed->title,
    )));
  }

  // Regardless of successful or not, indicate that this feed has been checked.
  db_update('aggregator_feed')
    ->fields(array(
    'checked' => REQUEST_TIME,
    'queued' => 0,
  ))
    ->condition('fid', $feed->fid)
    ->execute();

  // Expire old feed items.
  if (function_exists('aggregator_expire')) {
    aggregator_expire($feed);
  }
}