Commit 9384a8da authored by Dries's avatar Dries
Browse files

- Patch #402280 by mustafau, alex_b: parser should not update aggregator_feed() record.

parent 76882b6f
......@@ -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;
}
/**
......
......@@ -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:
......
......@@ -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);
......
......@@ -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;
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment