1. I would like to be able to assign ownership of imported nodes with imported email addresses.
2. I have an untested patch for node_import.module (v 1.50.2.3.2.13) here: http://drupal.pastebin.org/28418
3. The node import module queries the users table with email addresses to retrieve the uids for ownership.
4. Is there a function that can be used in place of db_query?
5. Is there a better way to accomplish my objective?
6. Can the patch be improved in some obvious way?
7. If I can get this to work I will submit it for a patch to be ported.

Comments

Robrecht Jacques’s picture

Status: Active » Needs review

The code you are changing is only for raw input (in which case the $type == 'node_import').

It is useful to to map a user using the email address in other places as well. There is a function called "node_import_userreference()" which is defined for that. Currently it only checks whether the value passed is an integer (in which case the uid is assumed) or if not, whether the string equals to the name of a user. We could extend this function to also look if the string passed matches an email.

This may be a patch, can check whether it works like you want?

Index: node_import.api.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/node_import/Attic/node_import.api.inc,v
retrieving revision 1.8.2.1.2.5
diff -u -r1.8.2.1.2.5 node_import.api.inc
--- node_import.api.inc 3 Jul 2007 08:29:35 -0000       1.8.2.1.2.5
+++ node_import.api.inc 18 Apr 2008 12:55:03 -0000
@@ -151,7 +151,7 @@
     if (is_numeric($name) && intval($name) > 0 && ($user = user_load(array('uid' => intval($name))))) {
       $uids[$name] = $user->uid;
     }
-    else if (($user = user_load(array('name' => $name)))) {
+    else if (($user = user_load(array('name' => $name))) || ($user = user_load(array('mail' => $name)))) {
       $uids[$name] = $user->uid;
     }
   }
Index: node_import.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/node_import/Attic/node_import.module,v
retrieving revision 1.50.2.3.2.13
diff -u -r1.50.2.3.2.13 node_import.module
--- node_import.module  17 Mar 2008 09:05:56 -0000      1.50.2.3.2.13
+++ node_import.module  18 Apr 2008 12:55:04 -0000
@@ -596,8 +596,8 @@
         $node->$fieldname = $value;
       }
       if ($match[$i] == 'name' && $type == 'node_import') {
-        if (($account = user_load(array('name' => $value))) ||
-            (is_numeric($value) && ($account = user_load(array('uid' => $value))))) {
+        if (($uid = node_import_userreference($value))) {
+          $account = user_load($uid);
           $node->uid = $account->uid;
           $node->name = $account->name;
         }

The first part extends the functionality of node_import_userreference(). The other part makes the module use the same function in case of raw input.

To answer your questions:
4. Yes: user_load(array('mail' => $value))
5. Yes: extend node_import_userreference()
6. Yes: use node_import_userreference() for raw input too (this is a bug in node_import.module)
7. Let me know if this patch would work.

Robrecht Jacques’s picture

Status: Needs review » Fixed

Will be included in node_import-5.x-1.6.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.