Recent we had to import a few thousands of users from our third party sites. The users details were available in a CSV file. We felt that user_import module was pretty much aligned to our requirement and the module does more than what we would infer from its name. A quick list of features that the module provides can be found in its project page at drupal.org. However one place where we felt the user_import was lacking is the enhanced support for token integration.
Every user account in our site has been associated to a content profile node. And the CCK fields of node has been mapped to user's first name, last name, etc. It was mandatory for our requirement to send the first name and last name along the account activation e-mail generated by user_import module. The support to use content profile fields as token in account activation e-mail was unavailable.
When we explored the code it was realized that the module supports profile module fields as token and we extended the same to content profile. Below is the simple fix we added to user_import module to handle our requirement.
Index: supported/user_import.inc =================================================================== --- supported/user_import.inc (revision 1608) +++ supported/user_import.inc (revision 1651) @@ -66,6 +66,16 @@ } } + if (module_exists('content_profile') && is_array($profile)) { + $content_profile_fields = $profile['content_profile']; + foreach ($content_profile_fields as $content_profile_field_name => $content_profile_field_value) { + $content_profile_field_name = explode(':', $content_profile_field_name); + $field_name = $content_profile_field_name[1]; + $field_value = $content_profile_field_value[0]; + $params['!' . $field_name] = $field_value; + } + } + $sent = drupal_mail('user_import', 'welcome', $account->mail, user_preferred_language($account), $params, variable_get('site_mail', NULL), TRUE); return; }
The applied fix has been working like a charm in our production sites. An issue addressing the same with patch has been created in drupal.org #1060394, If you think that this patch would be useful, feel free to add your comments in the issue queue.