diff options
author | Dries Buytaert <dries@buytaert.net> | 2009-10-12 15:54:59 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2009-10-12 15:54:59 +0000 |
commit | 9384a8da8b6d1d2b0ff1954aa1030d8f8c1b1529 (patch) | |
tree | 3c1856a81fe165f71631d9b0936e478e9a2ef67c /modules/aggregator | |
parent | 76882b6fc6e76a61605cc2074032f1f75fc320b8 (diff) | |
download | brdo-9384a8da8b6d1d2b0ff1954aa1030d8f8c1b1529.tar.gz brdo-9384a8da8b6d1d2b0ff1954aa1030d8f8c1b1529.tar.bz2 |
- Patch #402280 by mustafau, alex_b: parser should not update aggregator_feed() record.
Diffstat (limited to 'modules/aggregator')
-rw-r--r-- | modules/aggregator/aggregator.api.php | 17 | ||||
-rw-r--r-- | modules/aggregator/aggregator.fetcher.inc | 1 | ||||
-rw-r--r-- | modules/aggregator/aggregator.module | 39 | ||||
-rw-r--r-- | modules/aggregator/aggregator.parser.inc | 31 |
4 files changed, 60 insertions, 28 deletions
diff --git a/modules/aggregator/aggregator.api.php b/modules/aggregator/aggregator.api.php index cdf57b752..5fc07778d 100644 --- a/modules/aggregator/aggregator.api.php +++ b/modules/aggregator/aggregator.api.php @@ -82,6 +82,14 @@ function hook_aggregator_fetch_info() { * $feed->source_string contains the raw feed data as a string. Parse data * from $feed->source_string and expose it to other modules as an array of * data items on $feed->items. + * + * Feed format: + * - $feed->description (string) - description of the feed + * - $feed->image (string) - image for the feed + * - $feed->etag (string) - value of feed's entity tag header field + * - $feed->modified (UNIX timestamp) - value of feed's last modified header + * field + * - $feed->items (Array) - array of feed items. * * By convention, the common format for a single feed item is: * $item[key-name] = value; @@ -93,6 +101,9 @@ function hook_aggregator_fetch_info() { * AUTHOR (string) - the feed item's author * GUID (string) - RSS/Atom global unique identifier * LINK (string) - the feed item's URL + * + * @return + * TRUE if parsing was successful, FALSE otherwise. * * @see hook_aggregator_parse_info() * @see hook_aggregator_fetch() @@ -101,7 +112,11 @@ function hook_aggregator_fetch_info() { * @ingroup aggregator */ function hook_aggregator_parse($feed) { - $feed->items = mymodule_parse($feed->source_string); + if ($items = mymodule_parse($feed->source_string)) { + $feed->items = $items; + return TRUE; + } + return FALSE; } /** diff --git a/modules/aggregator/aggregator.fetcher.inc b/modules/aggregator/aggregator.fetcher.inc index fd4ba57f7..002209461 100644 --- a/modules/aggregator/aggregator.fetcher.inc +++ b/modules/aggregator/aggregator.fetcher.inc @@ -45,7 +45,6 @@ function aggregator_aggregator_fetch($feed) { break; case 301: $feed->url = $result->redirect_url; - $feed->redirected = TRUE; // Do not break here. case 200: case 302: diff --git a/modules/aggregator/aggregator.module b/modules/aggregator/aggregator.module index d8428f98d..096675dc9 100644 --- a/modules/aggregator/aggregator.module +++ b/modules/aggregator/aggregator.module @@ -585,20 +585,49 @@ function _aggregator_get_variables() { * An object describing the feed to be refreshed. */ function aggregator_refresh($feed) { + // Store feed URL to track changes. + $feed_url = $feed->url; + + // Fetch the feed. list($fetcher, $parser, $processors) = _aggregator_get_variables(); module_invoke($fetcher, 'aggregator_fetch', $feed); if ($feed->source_string !== FALSE) { // Parse the feed. - module_invoke($parser, 'aggregator_parse', $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, + 'checked' => REQUEST_TIME, + 'link' => empty($feed->link) ? $feed->url : $feed->link, + 'description' => empty($feed->description) ? '' : $feed->description, + 'image' => empty($feed->image) ? '' : $feed->image, + 'hash' => md5($feed->source_string), + 'etag' => empty($feed->etag) ? '' : $feed->etag, + 'modified' => empty($feed->modified) ? '' : $feed->modified, + )) + ->execute(); - // 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); + // 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)) { + $processors = variable_get('aggregator_processors', array('aggregator')); + foreach ($processors as $processor) { + module_invoke($processor, 'aggregator_process', $feed); + } } } } + // Expire old feed items. if (function_exists('aggregator_expire')) { aggregator_expire($feed); diff --git a/modules/aggregator/aggregator.parser.inc b/modules/aggregator/aggregator.parser.inc index aa616569f..fbd0deda4 100644 --- a/modules/aggregator/aggregator.parser.inc +++ b/modules/aggregator/aggregator.parser.inc @@ -44,32 +44,21 @@ function aggregator_aggregator_parse($feed) { } $etag = empty($feed->http_headers['ETag']) ? '' : $feed->http_headers['ETag']; - // Update the feed data. - db_merge('aggregator_feed') - ->key(array('fid' => $feed->fid)) - ->fields(array( - 'url' => $feed->url, - 'checked' => REQUEST_TIME, - 'link' => !empty($channel['link']) ? $channel['link'] : '', - 'description' => !empty($channel['description']) ? $channel['description'] : '', - 'image' => $image, - 'hash' => md5($feed->source_string), - 'etag' => $etag, - 'modified' => $modified, - )) - ->execute(); + + // Add parsed data to the feed object. + $feed->link = !empty($channel['LINK']) ? $channel['LINK'] : ''; + $feed->description = !empty($channel['DESCRIPTION']) ? $channel['DESCRIPTION'] : ''; + $feed->image = $image; + $feed->etag = $etag; + $feed->modified = $modified; // Clear the cache. cache_clear_all(); - if (isset($feed->redirected)) { - 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))); - + return TRUE; } + + return FALSE; } /** |