Again, thanks for getting this module upgraded for testing on D7

I just ran an import having patched module with http://drupal.org/node/1826014#comment-6663142

The import had settings
- send email YES
- activate accounts NO

Email msg was unmodified so the default welcome message was sent

Two problems with the email that arrived

1/ the user name was not inserted
2/ the email did not contain a link

here is one of the emails received after using User Import

---------
,

A site administrator at D7 Site has created an account for you. You may now
log in by clicking this link or copying and pasting it to your browser:

This link can only be used once to log in and will lead you to a page where
you can set your password.

After setting your password, you will be able to log in at
http://xxxxxxxxxx/user in the future using:

username:
password: Your password

-- D7 Site team

---------

and here is the welcome email sent by clicking on Add User

---------

fourfour,

A site administrator at D7 Site has created an account for you. You may now
log in by clicking this link or copying and pasting it to your browser:

http://xxxxxxxxxxx/user/reset/79/1352253030/RrIb0YcNbx_deau-k_3O8_ZQ9lpp...

This link can only be used once to log in and will lead you to a page where
you can set your password.

After setting your password, you will be able to log in at
http://xxxxxxxxxxxx/user in the future using:

username: fourfour
password: Your password

-- D7 Site team

CommentFileSizeAuthor
#5 1833960-user_import_tokens-5.patch540 bytestorrance123

Comments

warmth’s picture

I think this has something to do with this: #1840264: No entities support = no username = no login?

petednz’s picture

Hi warmth

I don't think so - the users do get a user name - it is constructed off the fields i specify in the import settings.

the users are 'saved' with a username

but the username is not being included in the email

i might naively suggest this is because the email is being triggered before the usernames are passed back to it, but I really don't know. Hoping Robert will pop by soon and shed some light on this.

petednz’s picture

This seems critical - we will take a look in the next day or so if no one else can.

warmth’s picture

Thank you!

torrance123’s picture

StatusFileSize
new540 bytes

From what I can tell, this bug is arising because user_import module and the standard user module are handling token replacement in the email differently. user_import module is using t() and user module is using token_replace().

Each of these functions expects a different format for the replacement variables but only the format for t() is being provided.

I think the method used by user module is probably more appropriate and user_import should probably be refactored to handle token replacements in the same way.

The short term fix, however, is to simply provide the $account object in the $params and therefore cater for both token replacement methods.

This is what the attached patch does.

torrance123’s picture

Status: Active » Needs review
warmth’s picture

After applying the patch
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'MYDB.profile_fields' doesn't exist: SELECT * FROM {profile_fields}; Array ( ) en _user_import_profile() (línea 926 de /home/MYSITE/www/site/sites/all/modules/user_import/user_import.admin.inc).

torrance123’s picture

Hi Warmth, I don't think this patch is responsible for the error you're seeing. For one, the error is occurring in a different file. But secondly, the patch is a single line that adds an account object that already existed prior to the patch to an array — not enough to cause a PDOException.

I suspect your issue is an incompatibility with profile module, which it looks like you have installed.

warmth’s picture

Do you mean Profile2?

torrance123’s picture

Yes, Profile2. But please don't derail this issue — open a new ticket for your error.

warmth’s picture

Yeah, I know pal. Thanks for point it out.

petednz’s picture

I don't know if this will count as 'tested' since Torrance and I are in the same team - but I have tested the system with the above patch and can confirm that the one-time user login now goes out correctly with username and one time link etc

robert - what else do you need/want to be ready to commit this

robert castelo’s picture

Status: Needs review » Needs work

Thanks for the detailed bug report.

Unfortunately the patch breaks the import if a custom email message is set:

Recoverable fatal error: Object of class stdClass could not be converted to string in user_import_mail() (line 101 of /Volumes/Sites/htdocs/drupal-7/sites/all/modules/my_development/user_import/supported/user_import.inc).

We need to look at converting the User Import to use tokens throughout.

robert castelo’s picture

Status: Needs work » Fixed

As the core welcome message is currently incompatible with User Import, but a welcome message can be set on a User Import import form, I've added an interim solution...

If Send Email has been enabled User Import checks that an email subject line and message have been set as part of the email.

Fixed in 7.x-1.0-beta2

Status: Fixed » Closed (fixed)

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