I am importing users from a system that did not force users to supply an email address. Many users did not. I would like to have an option to replace blank/invalid email addresses with a default, such as the site email address.

CommentFileSizeAuthor
#6 user_import.module.test58.51 KBcliffdiver1

Comments

DrewMathers’s picture

Category: feature » support

Drupal does not allow two users with the same email address. The requested feature cannot be implemented. I have changed the status to support request. Any ideas on how to handle the above situation?

davidwhthomas’s picture

I did a similar thing just now to import users without email addresses, I gave them a generated address like

blank1a2d7e@nomail.com

Here's the code to change to:
user_import.module line 1537

<?php
if ($setting['field_match'] == 'email') {
$email = trim($data[$column_id]);
/* start snippet */
/* allow no email by generating new default email */
if(!$email){
	$email = 'blank'.substr(md5(rand(0,100000000000)),0,6).'@nomail.com';
}
/* end snippet */
$errors = _user_import_validate_email($email);
}?>

hope that helps,

regards,

DT

robert castelo’s picture

Status: Active » Closed (fixed)

Or you could just generate the dummy email addresses in your speadsheet before importing.

cliffdiver1’s picture

I like your code snippet but can't get it to work. It would be extremely beneficial for me since I will be doing imports without email addresses very often.

Should this code be used INSTEAD OF line 1537? When I do that, my entire site breaks and gives me an error referencing line 1551 which is the code beginning with Default:

default:
_user_import_process($import);
drupal_set_message(t('Imported'));
break;

Any ideas?

davidwhthomas’s picture

No, the line number is obviously different in your version.

You'll need to look for the relevant lines and replace them with the code snippet.

search for

$email = trim($data[$column_id]);

or perhaps it's

$errors = _user_import_validate_email($email);

and insert the create email snippet from the above code.

cliffdiver1’s picture

StatusFileSize
new58.51 KB

Thanks for the quick response. Neither of those lines exists, though, in my version. I'm attaching that file (it's from 6.4) here.

Can you point me to the relevant line #?

Line 1537 in the unmodified file is:
$import['valid'] = 0;

jenniferannwalsh’s picture

I am pretty useless with Excel so I used this tool to generate almost 6,000 fake email addresses for my import: http://identitygenerator.com/

Just thought I'd post it here since I kept coming back to this thread as I tried to figure this out.

Thanks to Robert for the module!

Jen

EDIT: Note - After I wrote this I did a test import and noticed that some of the emails generated by the above tool had semi-colons in them. It was pretty easy to get rid of them with search & replace but thought I'd warn others about it.

Wassim Ghannoum’s picture

Version: 5.x-1.3 » 6.x-2.4

i fixed this issue by commenting the line 451 in user_import.module: if ($values['field_match'] == 'user-email') $email = TRUE;

and then i added $email = TRUE;

wusel’s picture

My tipp:
use the UID of the user and add "@example.com", when you build the fake-email-adress in #2. The UID is always unique.

Or create the users like http://drupal.org/node/1285276 (you don't need "Wusel_Step2_MemberlistMigration" at 'Import new users and their "Profile2"-fields from one CSV-file') and import an CSV-file with empty email-fields for that users!

Good luck!