Skip to content
Snippets Groups Projects
Commit cb7f5c66 authored by megachriz's avatar megachriz Committed by MegaChriz
Browse files

Issue #1891404 by MegaChriz, twistor, jenlampton: Add a mapper for Updated date (changed)

parent a11c4504
No related branches found
No related tags found
No related merge requests found
......@@ -634,6 +634,11 @@ function feeds_node_presave($node) {
}
$last_title = NULL;
$last_feeds = NULL;
// Update "changed" value if there was mapped to that.
if (isset($node->feeds_item->node_changed)) {
$node->changed = $node->feeds_item->node_changed;
}
}
/**
......
......@@ -239,6 +239,12 @@ class FeedsNodeProcessor extends FeedsProcessor {
case 'created':
$target_node->created = feeds_to_unixtime($value, REQUEST_TIME);
break;
case 'changed':
// The 'changed' value will be set on the node in feeds_node_presave().
// This is because node_save() always overwrites this value (though
// before invoking hook_node_presave()).
$target_node->feeds_item->node_changed = feeds_to_unixtime($value, REQUEST_TIME);
break;
case 'feeds_source':
// Get the class of the feed node importer's fetcher and set the source
// property. See feeds_node_update() how $node->feeds gets stored.
......@@ -305,6 +311,10 @@ class FeedsNodeProcessor extends FeedsProcessor {
'name' => t('Published date'),
'description' => t('The UNIX time when a node has been published.'),
);
$targets['changed'] = array(
'name' => t('Updated date'),
'description' => t('The Unix timestamp when a node has been last updated.'),
);
$targets['promote'] = array(
'name' => t('Promoted to front page'),
'description' => t('Boolean value, whether or not node is promoted to front page. (1 = promoted, 0 = not promoted)'),
......
......@@ -656,6 +656,46 @@ class FeedsRSStoNodesTest extends FeedsWebTestCase {
$this->assertNoText('Updated 2 nodes.');
}
/**
* Tests if the target "changed" works as expected.
*/
public function testChangedTarget() {
// Create and configure importer.
$this->createImporterConfiguration('Content CSV', 'csv');
$this->setSettings('csv', NULL, array('content_type' => '', 'import_period' => FEEDS_SCHEDULE_NEVER));
$this->setPlugin('csv', 'FeedsFileFetcher');
$this->setPlugin('csv', 'FeedsCSVParser');
$this->addMappings('csv', array(
0 => array(
'source' => 'title',
'target' => 'title',
),
// Borrow the timestamp value from the "created" column in the csv.
1 => array(
'source' => 'created',
'target' => 'changed',
),
));
// Import CSV file.
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content.csv');
$this->assertText('Created 2 nodes');
// Assert changed date of nodes.
$expected_values = array(
1 => array(
'changed' => 1251936720,
),
2 => array(
'changed' => 1251932360,
),
);
for ($i = 1; $i <= 2; $i++) {
$node = node_load($i);
$this->assertEqual($expected_values[$i]['changed'], $node->changed);
}
}
/**
* Tests the FeedsSource::pushImport() method.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment