From d47615c9d9c88b4b0c295a08fd9e6de49d97444c Mon Sep 17 00:00:00 2001
From: Alex Barth <alex_b@53995.no-reply.drupal.org>
Date: Tue, 13 Jul 2010 19:32:06 +0000
Subject: [PATCH] #853144 alex_b: Consistent use of replace vs update.

---
 CHANGELOG.txt                      |  1 +
 plugins/FeedsDataProcessor.inc     | 14 +++++++-------
 plugins/FeedsFeedNodeProcessor.inc |  5 +++--
 plugins/FeedsNodeProcessor.inc     | 17 +++++++++--------
 plugins/FeedsProcessor.inc         |  6 ++++++
 plugins/FeedsTermProcessor.inc     |  5 +++--
 plugins/FeedsUserProcessor.inc     |  6 +++---
 7 files changed, 32 insertions(+), 22 deletions(-)

diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 82f90a8a..f787011b 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -3,6 +3,7 @@
 Feeds 6.x 1.X XXXX
 ------------------
 
+- #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
   have to adjust your importer's File Fetcher settings.
diff --git a/plugins/FeedsDataProcessor.inc b/plugins/FeedsDataProcessor.inc
index 2ebaabee..bc83215a 100644
--- a/plugins/FeedsDataProcessor.inc
+++ b/plugins/FeedsDataProcessor.inc
@@ -254,7 +254,7 @@ class FeedsDataProcessor extends FeedsProcessor {
    */
   public function configDefaults() {
     return array(
-      'update_existing' => 0,
+      'update_existing' => FEEDS_SKIP_EXISTING,
       'expire' => FEEDS_EXPIRE_NEVER, // Don't expire items by default.
       'mappings' => array(),
     );
@@ -264,12 +264,6 @@ class FeedsDataProcessor extends FeedsProcessor {
    * Override parent::configForm().
    */
   public function configForm(&$form_state) {
-    $form['update_existing'] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Update existing items'),
-      '#description' => t('Check if existing items should be updated from the feed.'),
-      '#default_value' => $this->config['update_existing'],
-    );
     $period = drupal_map_assoc(array(FEEDS_EXPIRE_NEVER, 3600, 10800, 21600, 43200, 86400, 259200, 604800, 604800 * 4, 604800 * 12, 604800 * 24, 31536000), 'feeds_format_expire');
     $form['expire'] = array(
       '#type' => 'select',
@@ -278,6 +272,12 @@ class FeedsDataProcessor extends FeedsProcessor {
       '#description' => t('Select after how much time data records should be deleted. The timestamp target value will be used for determining the item\'s age, see Mapping settings.'),
       '#default_value' => $this->config['expire'],
     );
+    $form['update_existing'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Replace existing records'),
+      '#description' => t('If an existing record is found for an imported record, replace it. Existing records will be determined using mappings that are a "unique target".'),
+      '#default_value' => $this->config['update_existing'],
+    );
     return $form;
   }
 
diff --git a/plugins/FeedsFeedNodeProcessor.inc b/plugins/FeedsFeedNodeProcessor.inc
index 84fe4943..fb5b859a 100644
--- a/plugins/FeedsFeedNodeProcessor.inc
+++ b/plugins/FeedsFeedNodeProcessor.inc
@@ -137,10 +137,11 @@ class FeedsFeedNodeProcessor extends FeedsProcessor {
       '#options' => $types,
       '#default_value' => $this->config['content_type'],
     );
+    // @todo Implement real updating.
     $form['update_existing'] = array(
       '#type' => 'checkbox',
-      '#title' => t('Update existing items'),
-      '#description' => t('Check if existing items should be updated from the feed.'),
+      '#title' => t('Replace existing feed nodes'),
+      '#description' => t('If an existing node is found for an imported node, replace it. Existing nodes will be determined using mappings that are a "unique target".'),
       '#default_value' => $this->config['update_existing'],
     );
     return $form;
diff --git a/plugins/FeedsNodeProcessor.inc b/plugins/FeedsNodeProcessor.inc
index 75dadee3..5c88d34d 100644
--- a/plugins/FeedsNodeProcessor.inc
+++ b/plugins/FeedsNodeProcessor.inc
@@ -9,7 +9,8 @@
 // Create or delete FEEDS_NODE_BATCH_SIZE at a time.
 define('FEEDS_NODE_BATCH_SIZE', 50);
 
-// Updating mode for existing nodes.
+// Deprecated. Use FEEDS_SKIPE_EXISTING, FEEDS_REPLACE_EXISTNG,
+// FEEDS_UPDATE_EXISTING instead.
 define('FEEDS_NODE_SKIP_EXISTING', 0);
 define('FEEDS_NODE_REPLACE_EXISTING', 1);
 define('FEEDS_NODE_UPDATE_EXISTING', 2);
@@ -30,7 +31,7 @@ class FeedsNodeProcessor extends FeedsProcessor {
     while ($item = $batch->shiftItem()) {
 
       // Create/update if item does not exist or update existing is enabled.
-      if (!($nid = $this->existingItemId($item, $source)) || ($this->config['update_existing'] != FEEDS_NODE_SKIP_EXISTING)) {
+      if (!($nid = $this->existingItemId($item, $source)) || ($this->config['update_existing'] != FEEDS_SKIP_EXISTING)) {
         $node = $this->buildNode($nid, $source->feed_nid);
 
         // Only proceed if item has actually changed.
@@ -148,7 +149,7 @@ class FeedsNodeProcessor extends FeedsProcessor {
     return array(
       'content_type' => $type,
       'input_format' => FILTER_FORMAT_DEFAULT,
-      'update_existing' => FEEDS_NODE_SKIP_EXISTING,
+      'update_existing' => FEEDS_SKIP_EXISTING,
       'expire' => FEEDS_EXPIRE_NEVER,
       'mappings' => array(),
       'author' => 0,
@@ -199,11 +200,11 @@ class FeedsNodeProcessor extends FeedsProcessor {
     $form['update_existing'] = array(
       '#type' => 'radios',
       '#title' => t('Update existing items'),
-      '#description' => t('Select how existing nodes should be updated.'),
+      '#description' => t('Select how existing nodes should be updated. Existing nodes will be determined using mappings that are a "unique target".'),
       '#options' => array(
-        FEEDS_NODE_SKIP_EXISTING => 'Do not update existing nodes',
-        FEEDS_NODE_REPLACE_EXISTING => 'Replace existing nodes',
-        FEEDS_NODE_UPDATE_EXISTING => 'Update existing nodes (slower than replacing them)',
+        FEEDS_SKIP_EXISTING => 'Do not update existing nodes',
+        FEEDS_REPLACE_EXISTING => 'Replace existing nodes',
+        FEEDS_UPDATE_EXISTING => 'Update existing nodes (slower than replacing them)',
       ),
       '#default_value' => $this->config['update_existing'],
     );
@@ -319,7 +320,7 @@ class FeedsNodeProcessor extends FeedsProcessor {
       $populate = TRUE;
     }
     else {
-      if ($this->config['update_existing'] == FEEDS_NODE_UPDATE_EXISTING) {
+      if ($this->config['update_existing'] == FEEDS_UPDATE_EXISTING) {
         $node = node_load($nid, NULL, TRUE);
       }
       else {
diff --git a/plugins/FeedsProcessor.inc b/plugins/FeedsProcessor.inc
index 69da4beb..be1e0c3b 100644
--- a/plugins/FeedsProcessor.inc
+++ b/plugins/FeedsProcessor.inc
@@ -1,6 +1,12 @@
 <?php
 // $Id$
 
+
+// Update mode for existing items.
+define('FEEDS_SKIP_EXISTING', 0);
+define('FEEDS_REPLACE_EXISTING', 1);
+define('FEEDS_UPDATE_EXISTING', 2);
+
 /**
  * Abstract class, defines interface for processors.
  */
diff --git a/plugins/FeedsTermProcessor.inc b/plugins/FeedsTermProcessor.inc
index 1abd6212..9ed5b421 100644
--- a/plugins/FeedsTermProcessor.inc
+++ b/plugins/FeedsTermProcessor.inc
@@ -145,10 +145,11 @@ class FeedsTermProcessor extends FeedsProcessor {
       '#options' => $options,
       '#default_value' => $this->config['vocabulary'],
     );
+    // @todo Implement true updating.
     $form['update_existing'] = array(
       '#type' => 'checkbox',
-      '#title' => t('Update existing items'),
-      '#description' => t('Check if existing terms should be updated from the feed.'),
+      '#title' => t('Replace existing terms'),
+      '#description' => t('If an existing term is found for an imported term, replace it. Existing terms will be determined using mappings that are a "unique target".'),
       '#default_value' => $this->config['update_existing'],
     );
     return $form;
diff --git a/plugins/FeedsUserProcessor.inc b/plugins/FeedsUserProcessor.inc
index ff4f8b33..6a1ef9c8 100644
--- a/plugins/FeedsUserProcessor.inc
+++ b/plugins/FeedsUserProcessor.inc
@@ -145,11 +145,11 @@ class FeedsUserProcessor extends FeedsProcessor {
         '#options' => $roles,
       );
     }
-
+    // @todo Implement true updating.
     $form['update_existing'] = array(
       '#type' => 'checkbox',
-      '#title' => t('Update existing users'),
-      '#description' => t('Check if existing users should be updated from imported data.'),
+      '#title' => t('Replace existing users'),
+      '#description' => t('If an existing user is found for an imported user, replace it. Existing users will be determined using mappings that are a "unique target".'),
       '#default_value' => $this->config['update_existing'],
     );
     return $form;
-- 
GitLab