- Patch #52015 by mustafau: update timestamps for aggregator news items.
parent
df7bcec717
commit
f6a4263476
|
@ -774,9 +774,8 @@ function aggregator_parse_feed(&$data, $feed) {
|
|||
$item['DESCRIPTION'] = $item['CONTENT'];
|
||||
}
|
||||
|
||||
// Try to resolve and parse the item's publication date. If no date is
|
||||
// found, use the current date instead.
|
||||
$date = 'now';
|
||||
// Try to resolve and parse the item's publication date.
|
||||
$date = '';
|
||||
foreach (array('PUBDATE', 'DC:DATE', 'DCTERMS:ISSUED', 'DCTERMS:CREATED', 'DCTERMS:MODIFIED', 'ISSUED', 'CREATED', 'MODIFIED', 'PUBLISHED', 'UPDATED') as $key) {
|
||||
if (!empty($item[$key])) {
|
||||
$date = $item[$key];
|
||||
|
@ -788,26 +787,26 @@ function aggregator_parse_feed(&$data, $feed) {
|
|||
|
||||
if ($timestamp <= 0) {
|
||||
$timestamp = aggregator_parse_w3cdtf($date); // Aggregator_parse_w3cdtf() returns FALSE on failure.
|
||||
if (!$timestamp) {
|
||||
// Better than nothing.
|
||||
$timestamp = time();
|
||||
}
|
||||
}
|
||||
|
||||
// Save this item. Try to avoid duplicate entries as much as possible. If
|
||||
// we find a duplicate entry, we resolve it and pass along its ID is such
|
||||
// that we can update it if needed.
|
||||
if (!empty($guid)) {
|
||||
$entry = db_fetch_object(db_query("SELECT iid FROM {aggregator_item} WHERE fid = %d AND guid = '%s'", $feed['fid'], $guid));
|
||||
$entry = db_fetch_object(db_query("SELECT iid, timestamp FROM {aggregator_item} WHERE fid = %d AND guid = '%s'", $feed['fid'], $guid));
|
||||
}
|
||||
else if ($link && $link != $feed['link'] && $link != $feed['url']) {
|
||||
$entry = db_fetch_object(db_query("SELECT iid FROM {aggregator_item} WHERE fid = %d AND link = '%s'", $feed['fid'], $link));
|
||||
$entry = db_fetch_object(db_query("SELECT iid, timestamp FROM {aggregator_item} WHERE fid = %d AND link = '%s'", $feed['fid'], $link));
|
||||
}
|
||||
else {
|
||||
$entry = db_fetch_object(db_query("SELECT iid FROM {aggregator_item} WHERE fid = %d AND title = '%s'", $feed['fid'], $title));
|
||||
$entry = db_fetch_object(db_query("SELECT iid, timestamp FROM {aggregator_item} WHERE fid = %d AND title = '%s'", $feed['fid'], $title));
|
||||
}
|
||||
|
||||
if (!$timestamp) {
|
||||
$timestamp = isset($entry->timestamp) ? $entry->timestamp : time();
|
||||
}
|
||||
$item += array('AUTHOR' => '', 'DESCRIPTION' => '');
|
||||
aggregator_save_item(array('iid' => (isset($entry->iid) ? $entry->iid: ''), 'fid' => $feed['fid'], 'timestamp' => $timestamp, 'title' => $title, 'link' => $link, 'author' => $item['AUTHOR'], 'description' => $item['DESCRIPTION'], 'guid' => $guid));
|
||||
aggregator_save_item(array('iid' => (isset($entry->iid) ? $entry->iid : ''), 'fid' => $feed['fid'], 'timestamp' => $timestamp, 'title' => $title, 'link' => $link, 'author' => $item['AUTHOR'], 'description' => $item['DESCRIPTION'], 'guid' => $guid));
|
||||
}
|
||||
|
||||
// Remove all items that are older than flush item timer.
|
||||
|
|
|
@ -195,6 +195,40 @@ EOF;
|
|||
file_save_data($opml, $path);
|
||||
return $path;
|
||||
}
|
||||
|
||||
function getRSS091Sample() {
|
||||
$feed = <<<EOT
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<rss version="0.91">
|
||||
<channel>
|
||||
<title>Example</title>
|
||||
<link>http://example.com</link>
|
||||
<description>Example updates</description>
|
||||
<language>en-us</language>
|
||||
<copyright>Copyright 2000, Example team.</copyright>
|
||||
<managingEditor>editor@example.com</managingEditor>
|
||||
<webMaster>webmaster@example.com</webMaster>
|
||||
<image>
|
||||
<title>Example</title>
|
||||
<url>http://example.com/images/druplicon.png</url>
|
||||
<link>http://example.com</link>
|
||||
<width>88</width>
|
||||
<height>100</height>
|
||||
<description>Example updates</description>
|
||||
</image>
|
||||
<item>
|
||||
<title>Example turns one</title>
|
||||
<link>http://example.com/example-turns-one</link>
|
||||
<description>Example turns one.</description>
|
||||
</item>
|
||||
</channel>
|
||||
</rss>
|
||||
EOT;
|
||||
|
||||
$path = file_directory_path() . '/rss091.xml';
|
||||
file_save_data($feed, $path);
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
|
||||
class AddFeedTestCase extends AggregatorTestCase {
|
||||
|
@ -324,6 +358,31 @@ class UpdateFeedItemTestCase extends AggregatorTestCase {
|
|||
|
||||
// Delete feed.
|
||||
$this->deleteFeed($feed);
|
||||
|
||||
// Test updating feed items without valid timestamp information.
|
||||
$edit = array(
|
||||
'title' => "Feed without publish timestamp",
|
||||
'url' => file_create_url($this->getRSS091Sample()),
|
||||
);
|
||||
$this->drupalGet($edit['url']);
|
||||
$this->assertResponse(array(200), t('URL !url is accessible', array('!url' => $edit['url'])));
|
||||
|
||||
$this->drupalPost('admin/content/aggregator/add/feed', $edit, t('Save'));
|
||||
$this->assertRaw(t('The feed %name has been added.', array('%name' => $edit['title'])), t('The feed !name has been added.', array('!name' => $edit['title'])));
|
||||
|
||||
$feed = db_fetch_object(db_query("SELECT * FROM {aggregator_feed} WHERE url = '%s'", $edit['url']));
|
||||
$this->drupalGet('admin/content/aggregator/update/' . $feed->fid);
|
||||
|
||||
$before = db_result(db_query('SELECT timestamp FROM {aggregator_item} WHERE fid = %d', $feed->fid));
|
||||
|
||||
// Sleep for 3 second.
|
||||
sleep(3);
|
||||
db_query("UPDATE {aggregator_feed} SET checked = 0, hash = '', etag = '', modified = 0 WHERE fid = %d", $feed->fid);
|
||||
$this->drupalGet('admin/content/aggregator/update/' . $feed->fid);
|
||||
|
||||
$after = db_result(db_query('SELECT timestamp FROM {aggregator_item} WHERE fid = %d', $feed->fid));
|
||||
|
||||
$this->assertTrue($before === $after, t('Publish timestamp of feed item was not updated (!before === !after)', array('!before' => $before, '!after' => $after)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue