From dd9ef226022d555096f818d7d596f1bef3702e55 Mon Sep 17 00:00:00 2001
From: Alex Barth <alex_b@53995.no-reply.drupal.org>
Date: Sat, 19 Jun 2010 15:57:13 +0000
Subject: [PATCH] Consolidate loadMappers() after latest commit. Update
 comments.

---
 plugins/FeedsNodeProcessor.inc | 20 ------------------
 plugins/FeedsProcessor.inc     | 38 +++++++++++++++++++++++++++++-----
 plugins/FeedsUserProcessor.inc | 21 +------------------
 3 files changed, 34 insertions(+), 45 deletions(-)

diff --git a/plugins/FeedsNodeProcessor.inc b/plugins/FeedsNodeProcessor.inc
index 1b3051a9..56e67365 100644
--- a/plugins/FeedsNodeProcessor.inc
+++ b/plugins/FeedsNodeProcessor.inc
@@ -294,26 +294,6 @@ class FeedsNodeProcessor extends FeedsProcessor {
     return 0;
   }
 
-  /**
-   * Loads on-behalf implementations from mappers/
-   */
-  protected static function loadMappers() {
-    static $loaded = FALSE;
-
-    if (!$loaded) {
-      $path = drupal_get_path('module', 'feeds') .'/mappers';
-      $files = drupal_system_listing('.*\.inc$', $path, 'name', 0);
-      foreach ($files as $file) {
-        if (strstr($file->filename, '/mappers/')) {
-  	      require_once("./$file->filename");
-        }
-      }
-      // Rebuild cache.
-      module_implements('', FALSE, TRUE);
-    }
-    $loaded = TRUE;
-  }
-
   /**
    * Create MD5 hash of $item array.
    * @return Always returns a hash, even with empty, NULL, FALSE:
diff --git a/plugins/FeedsProcessor.inc b/plugins/FeedsProcessor.inc
index a0b15770..a33991fd 100644
--- a/plugins/FeedsProcessor.inc
+++ b/plugins/FeedsProcessor.inc
@@ -62,10 +62,12 @@ abstract class FeedsProcessor extends FeedsPlugin {
   }
 
   /**
-   * Execute mapping on an item. This method encapsulates the central mapping
-   * functionality. When an item is processed, it is passed through map() where
-   * the properties of $source_item are mapped onto $target_item following
-   * the processor's mapping configuration.
+   * Execute mapping on an item.
+   *
+   * This method encapsulates the central mapping functionality. When an item is
+   * processed, it is passed through map() where the properties of $source_item
+   * are mapped onto $target_item following the processor's mapping
+   * configuration.
    *
    * For each mapping FeedsParser::getSourceElement() is executed to retrieve
    * the source element, then FeedsProcessor::setTargetElement() is invoked
@@ -76,9 +78,10 @@ abstract class FeedsProcessor extends FeedsPlugin {
    *
    * @ingroup mappingapi
    *
+   * @see hook_feeds_data_processor_targets_alter()
    * @see hook_feeds_node_processor_targets_alter()
    * @see hook_feeds_term_processor_targets_alter()
-   * @see hook_feeds_data_processor_targets_alter()
+   * @see hook_feeds_user_processor_targets_alter()
    */
   protected function map($source_item, $target_item = NULL) {
 
@@ -245,4 +248,29 @@ abstract class FeedsProcessor extends FeedsPlugin {
     }
     return $targets;
   }
+
+  /**
+   * Loads on-behalf implementations from mappers/ directory.
+   *
+   * FeedsProcessor::map() does not load from mappers/ as only node and user
+   * processor ship with on-behalf implementations.
+   *
+   * @see FeedsNodeProcessor::map()
+   * @see FeedsUserProcessor::map()
+   */
+  protected static function loadMappers() {
+    static $loaded = FALSE;
+    if (!$loaded) {
+      $path = drupal_get_path('module', 'feeds') .'/mappers';
+      $files = drupal_system_listing('.*\.inc$', $path, 'name', 0);
+      foreach ($files as $file) {
+        if (strstr($file->filename, '/mappers/')) {
+          require_once("./$file->filename");
+        }
+      }
+      // Rebuild cache.
+      module_implements('', FALSE, TRUE);
+    }
+    $loaded = TRUE;
+  }
 }
diff --git a/plugins/FeedsUserProcessor.inc b/plugins/FeedsUserProcessor.inc
index ea088900..ff4f8b33 100644
--- a/plugins/FeedsUserProcessor.inc
+++ b/plugins/FeedsUserProcessor.inc
@@ -93,26 +93,6 @@ class FeedsUserProcessor extends FeedsProcessor {
     throw new Exception(t('User processor does not support deleting users.'));
   }
 
-  /**
-   * Loads on-behalf implementations from mappers/
-   */
-  protected static function loadMappers() {
-    static $loaded = FALSE;
-
-    if (!$loaded) {
-      $path = drupal_get_path('module', 'feeds') .'/mappers';
-      $files = drupal_system_listing('.*\.inc$', $path, 'name', 0);
-      foreach ($files as $file) {
-        if (strstr($file->filename, '/mappers/')) {
-              require_once("./$file->filename");
-        }
-      }
-      // Rebuild cache.
-      module_implements('', FALSE, TRUE);
-    }
-    $loaded = TRUE;
-  }
-
   /**
    * Execute mapping on an item.
    */
@@ -124,6 +104,7 @@ class FeedsUserProcessor extends FeedsProcessor {
     $target_account->status = $this->config['status'];
 
     // Have parent class do the iterating.
+    self::loadMappers();
     return parent::map($source_item, $target_account);
   }
 
-- 
GitLab