Skip to content
Snippets Groups Projects
Commit 453dddfa authored by mikran's avatar mikran Committed by MegaChriz
Browse files

Issue #1950182 by mikran, MegaChriz, twistor: Only update when mapped fields are updated

parent d0ac307e
No related branches found
No related tags found
No related merge requests found
...@@ -101,6 +101,13 @@ class FeedsCSVParser extends FeedsParser { ...@@ -101,6 +101,13 @@ class FeedsCSVParser extends FeedsParser {
return parent::getSourceElement($source, $result, drupal_strtolower($element_key)); return parent::getSourceElement($source, $result, drupal_strtolower($element_key));
} }
/**
* Override parent::getMappingSourceList() to use only lower keys.
*/
public function getMappingSourceList() {
return array_map('drupal_strtolower', parent::getMappingSourceList());
}
/** /**
* Define defaults. * Define defaults.
*/ */
......
...@@ -119,6 +119,21 @@ abstract class FeedsParser extends FeedsPlugin { ...@@ -119,6 +119,21 @@ abstract class FeedsParser extends FeedsPlugin {
return $sources; return $sources;
} }
/**
* Get list of mapped sources.
*
* @return array
* List of mapped source names in an array.
*/
public function getMappingSourceList() {
$mappings = feeds_importer($this->id)->processor->config['mappings'];
$sources = array();
foreach ($mappings as $mapping) {
$sources[] = $mapping['source'];
}
return $sources;
}
/** /**
* Get an element identified by $element_key of the given item. * Get an element identified by $element_key of the given item.
* The element key corresponds to the values in the array returned by * The element key corresponds to the values in the array returned by
......
...@@ -1052,12 +1052,13 @@ abstract class FeedsProcessor extends FeedsPlugin { ...@@ -1052,12 +1052,13 @@ abstract class FeedsProcessor extends FeedsPlugin {
* Include mappings as a change in mappings may have an affect on the item * Include mappings as a change in mappings may have an affect on the item
* produced. * produced.
* *
* @return Always returns a hash, even with empty, NULL, FALSE: * @return string
* Empty arrays return 40cd750bba9870f18aada2478b24840a * A hash is always returned, even when the item is empty, NULL or FALSE.
* Empty/NULL/FALSE strings return d41d8cd98f00b204e9800998ecf8427e
*/ */
protected function hash($item) { protected function hash($item) {
return hash('md5', serialize($item) . serialize($this->config['mappings'])); $sources = feeds_importer($this->id)->parser->getMappingSourceList();
$mapped_item = array_intersect_key($item, array_flip($sources));
return hash('md5', serialize($mapped_item) . serialize($this->config['mappings']));
} }
/** /**
......
name,mail,since,password
Morticia,morticia@example.com,1363959643,mort
Fester,fester@example.com,1363959643,fest
Gomez,gomez@example.com,1363959643,gome
Wednesday,wednesdayexample.com,1363959643,wedn
Pugsley,pugsley@example,1363959643,pugs
...@@ -668,4 +668,37 @@ class FeedsRSStoNodesTest extends FeedsWebTestCase { ...@@ -668,4 +668,37 @@ class FeedsRSStoNodesTest extends FeedsWebTestCase {
$this->assertEqual(10, db_query("SELECT COUNT(*) FROM {node}")->fetchField()); $this->assertEqual(10, db_query("SELECT COUNT(*) FROM {node}")->fetchField());
} }
/**
* Tests if target item is not updated when only non-mapped data on the source changed.
*/
public function testIrrelevantUpdate() {
// Include FeedsProcessor.inc so processor related constants are available.
module_load_include('inc', 'feeds', 'plugins/FeedsProcessor');
// Attach to standalone importer and configure.
$this->setSettings('syndication', NULL, array('content_type' => ''));
$this->setPlugin('syndication', 'FeedsFileFetcher');
$this->setPlugin('syndication', 'FeedsCSVParser');
$this->removeMappings('syndication', $this->getCurrentMappings('syndication'));
$this->addMappings('syndication', array(
0 => array(
'source' => 'name',
'target' => 'title',
'unique' => TRUE,
),
));
// Import file.
$this->importFile('syndication', $this->absolutePath() . '/tests/feeds/users.csv');
$this->assertText('Created 5 nodes');
// Ensure that no nodes are updated when only non-mapped columns changed.
$this->setSettings('syndication', 'FeedsNodeProcessor', array(
'skip_hash_check' => FALSE,
'update_existing' => FEEDS_UPDATE_EXISTING,
));
$this->importFile('syndication', $this->absolutePath() . '/tests/feeds/users_updated.csv');
$this->assertText('There are no new nodes.');
}
} }
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