From 4966c0de45501290a09ae0514adedf53227f5547 Mon Sep 17 00:00:00 2001
From: Alex Barth <alex_b@53995.no-reply.drupal.org>
Date: Wed, 17 Feb 2010 22:58:18 +0000
Subject: [PATCH] Support mapping to OpenID, using OpenID as a unique mapping
 target.

---
 CHANGELOG.txt                  |  1 +
 plugins/FeedsUserProcessor.inc | 29 ++++++++++++++++++++++++-----
 2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 1c2a3ebe..62498f13 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -3,6 +3,7 @@
 Feeds 6.x 1.0 xxxxx xx, xxxx-xx-xx
 ----------------------------------
 
+- alex_b: Support mapping to OpenID, using OpenID as a unique mapping target.
 - alex_b: Handle exceptions outside of Importer/Source facade methods.
 - #600584 alexb: Use Batch API. NOTE: third party plugins/extensions
   implementing FeedsProcessor::process(), FeedsProcessor::clear() or
diff --git a/plugins/FeedsUserProcessor.inc b/plugins/FeedsUserProcessor.inc
index 4bdde838..4f60bfe0 100644
--- a/plugins/FeedsUserProcessor.inc
+++ b/plugins/FeedsUserProcessor.inc
@@ -38,8 +38,17 @@ class FeedsUserProcessor extends FeedsProcessor {
         }
 
         // Save the user.
-        // @todo Is this really the best way to use this function?
         user_save($account, (array) $account);
+        if ($account->uid && $account->openid) {
+          $authmap = array(
+            'uid' => $account->uid,
+            'module' => 'openid',
+            'authname' => $account->openid,
+          );
+          if (SAVED_UPDATED != drupal_write_record('authmap', $authmap, array('uid', 'module'))) {
+            drupal_write_record('authmap', $authmap);
+          }
+        }
 
         if ($uid) {
           $updated++;
@@ -164,6 +173,13 @@ class FeedsUserProcessor extends FeedsProcessor {
         'description' => t('The created (e. g. joined) data of the user.'),
        ),
     );
+    if (module_exists('openid')) {
+      $targets['openid'] = array(
+        'name' => t('OpenID identifier'),
+        'description' => t('The OpenID identifier of the user. <strong>CAUTION:</strong> Use only for migration purposes, misconfiguration of the OpenID identifier can lead to severe security breaches like users gaining access to accounts other than their own.'),
+        'optional_unique' => TRUE,
+       );
+    }
     return $targets;
   }
 
@@ -177,15 +193,18 @@ class FeedsUserProcessor extends FeedsProcessor {
     foreach ($this->uniqueTargets($source_item) as $target => $value) {
       switch ($target) {
         case 'name':
-          $nid = db_result(db_query('SELECT uid FROM {users} WHERE name = "%s"', $value));
+          $uid = db_result(db_query('SELECT uid FROM {users} WHERE name = "%s"', $value));
           break;
         case 'mail':
-          $nid = db_result(db_query('SELECT uid FROM {users} WHERE mail = "%s"', $value));
+          $uid = db_result(db_query('SELECT uid FROM {users} WHERE mail = "%s"', $value));
+          break;
+        case 'openid':
+          $uid = db_result(db_query("SELECT uid FROM {authmap} WHERE authname = '%s' AND module = 'openid'", $value));
           break;
       }
-      if ($nid) {
+      if ($uid) {
         // Return with the first nid found.
-        return $nid;
+        return $uid;
       }
     }
     return 0;
-- 
GitLab