From 6f4105c17b52fb680524c041c34fd1b784196173 Mon Sep 17 00:00:00 2001
From: Alex Barth <alex_b@53995.no-reply.drupal.org>
Date: Sun, 18 Jul 2010 18:33:43 +0000
Subject: [PATCH] #853194 andrewlevine, alex_b: Mapping: don't reset all
 targets.

---
 CHANGELOG.txt                  |  1 +
 plugins/FeedsNodeProcessor.inc |  4 ++++
 plugins/FeedsProcessor.inc     | 10 +++++-----
 tests/feeds.test               | 25 ++++++++++++++++++++++---
 4 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index f787011b..301c425d 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -3,6 +3,7 @@
 Feeds 6.x 1.X XXXX
 ------------------
 
+- #853194 andrewlevine, alex_b: Mapping: don't reset all targets.
 - #853144 alex_b: Consistent use of "replace" vs "update".
 - #850998 alex_b: Clean up file upload form. Note: If you supply file paths
   directly in the textfield rather than uploading them through the UI, you will
diff --git a/plugins/FeedsNodeProcessor.inc b/plugins/FeedsNodeProcessor.inc
index b8960154..8d7dfc24 100644
--- a/plugins/FeedsNodeProcessor.inc
+++ b/plugins/FeedsNodeProcessor.inc
@@ -259,6 +259,10 @@ class FeedsNodeProcessor extends FeedsProcessor {
       );
     }
     $targets += array(
+      'uid' => array(
+        'name' => t('User ID'),
+        'description' => t('The Drupal user ID of the node author.'),
+      ),
       'status' => array(
         'name' => t('Published status'),
         'description' => t('Whether a node is published or not. 1 stands for published, 0 for not published.'),
diff --git a/plugins/FeedsProcessor.inc b/plugins/FeedsProcessor.inc
index be1e0c3b..4f049d77 100644
--- a/plugins/FeedsProcessor.inc
+++ b/plugins/FeedsProcessor.inc
@@ -108,12 +108,12 @@ abstract class FeedsProcessor extends FeedsPlugin {
       $target_item = (object)$target_item;
       $convert_to_array = TRUE;
     }
-    foreach ($targets[$this->id] as $target_name => $target) {
-      if (isset($target['real_target']) && isset($target_item->$target['real_target'])) {
-        unset($target_item->$target['real_target']);
+    foreach ($this->config['mappings'] as $mapping) {
+      if (isset($targets[$mapping['target']]['real_target'])) {
+        unset($target_item->{$targets[$mapping['target']]['real_target']});
       }
-      else if (isset($target_item->$target_name)) {
-        unset($target_item->$target_name);
+      elseif (isset($target_item->{$mapping['target']})) {
+        unset($target_item->{$mapping['target']});
       }
     }
     if ($convert_to_array) {
diff --git a/tests/feeds.test b/tests/feeds.test
index 3adae982..7ebe943f 100644
--- a/tests/feeds.test
+++ b/tests/feeds.test
@@ -33,7 +33,7 @@ class FeedsRSStoNodesTest extends FeedsWebTestCase {
     $this->drupalLogin(
       $this->drupalCreateUser(
         array(
-          'administer feeds', 'administer nodes',
+          'administer feeds', 'administer nodes', 'administer content types',
         )
       )
     );
@@ -133,7 +133,7 @@ class FeedsRSStoNodesTest extends FeedsWebTestCase {
     $this->assertText('The first major change is switching');
 
     // Assert DB status.
-    $count = db_result(db_query("SELECT COUNT(*) FROM {feeds_node_item}"));
+    $count = db_result(db_query("SELECT COUNT(*) FROM {node} n INNER JOIN {feeds_node_item} fn ON n.nid = fn.nid"));
     $this->assertEqual($count, 10, 'Accurate number of items in database.');
 
     // Assert default input format on first imported feed node.
@@ -145,10 +145,29 @@ class FeedsRSStoNodesTest extends FeedsWebTestCase {
     $this->assertText('There is no new content.');
 
     // Assert DB status, there still shouldn't be more than 10 items.
-    $count = db_result(db_query("SELECT COUNT(*) FROM {feeds_node_item}"));
+    $count = db_result(db_query("SELECT COUNT(*) FROM {node} n INNER JOIN {feeds_node_item} fn ON n.nid = fn.nid"));
     $this->assertEqual($count, 10, 'Accurate number of items in database.');
 
+    // All of the above tests should have produced published nodes, set default
+    // to unpublished, import again.
+    $count = db_result(db_query("SELECT COUNT(*) FROM {node} n INNER JOIN {feeds_node_item} fn ON n.nid = fn.nid WHERE n.status = 1"));
+    $this->assertEqual($count, 10, 'All items are published.');
+    $edit = array(
+      'node_options[status]' => FALSE,
+    );
+    $this->drupalPost('admin/content/node-type/story', $edit, t('Save content type'));
+    $this->drupalPost('node/'. $nid .'/delete-items', array(), 'Delete');
+    $this->drupalPost('node/'. $nid .'/import', array(), 'Import');
+    $count = db_result(db_query("SELECT COUNT(*) FROM {node} n INNER JOIN {feeds_node_item} fn ON n.nid = fn.nid WHERE n.status = 0"));
+    $this->assertEqual($count, 10, 'No items are published.');
+    $edit = array(
+      'node_options[status]' => TRUE,
+    );
+    $this->drupalPost('admin/content/node-type/story', $edit, t('Save content type'));
+    $this->drupalPost('node/'. $nid .'/delete-items', array(), 'Delete');
+
     // Enable replace existing and import updated feed file.
+    $this->drupalPost('node/'. $nid .'/import', array(), 'Import');
     $this->setSettings('syndication', 'FeedsNodeProcessor', array('update_existing' => 1));
     $feed_url = $GLOBALS['base_url'] .'/'. drupal_get_path('module', 'feeds') .'/tests/feeds/developmentseed_changes.rss2';
     $this->editFeedNode($nid, $feed_url);
-- 
GitLab