The User Import Framework (uif) module provides simple, extensible user import via CSV (comma-separated value) files. The guiding philosophy is to make the import process as simple as possible for the end-user (the user doing the import). Hooks allow the developer (you) to add the bells and whistles you need, e.g. content_profile (D6), core user fields or profile2 (D7) support, while providing a framework which takes care of the tedious aspects of the job (forms, input parsing).

User import is a two-step process. 1) The user chooses a csv file, along with specifying the number of records they'd like to preview. The user can also choose whether new users get a welcome email. 2) If happy with the preview, user submits the form again and users are created (or updated, if a user already exists).

User Import Framework uses the Batch API to avoid timeout and out-of-memory errors during import.

Alternatives

Migrate module (http://drupal.org/project/migrate) is a robust and thorough implementation of data migration that handles users, nodes, and any other type of content from a variety of sources. It is flexible and well-maintained. If your requirements are involved or the user (perhaps you) is technically proficient, this is a powerful user import solution.

The User Import module (http://drupal.org/project/user_import) is another option. User Import has a great deal of functionality built in, and endeavors to integrate with several other modules. You may want to check its maintenance status.

This module, unlike the solutions above, includes only critical user interface elements, with the goal of simplifying the user import experience for non-technical administrators. Added functionality specific to your website is provided by you, the developer, in the specific areas you need it.

Installation

  1. Copy the uif directory to the modules folder in your installation.
  2. Enable the module using Administer -> Modules (/admin/build/modules)
  3. Enable 'import users' permission for any role(s) you want to be able to do imports.
  4. Go to User management -> Import users (/admin/user/uif or /admin/people/uif in D7) and import some users.

Basic Setup

Out of the box, this module supports import of {user} table fields such as mail, name, pass, roles, created, timezone, and language. Of these, only an email address (mail) is required. If no name (username) is provided, the module creates a unique one based on the email. If no pass (password) is provided, a random one is generated.

This module also supports the import of most core Field module field types, including text, integer, float, decimal, and taxonomy terms.

Only CSV file format is supported. The import file must have a header row, and it must contain a column labeled "mail" (no quotes). Additional header columns should contain the exact name of the corresponding field. For {user} table fields, these would be, for example, "name", "pass", "language", etc. For Field module fields, these might be "field_some_text", "field_some_number" etc as they correspond to the field names present in the site.

Header case is ignored (note: developers should always use lower case in their code when referring to data).

To import roles, add a column labeled "roles", and include the role(s) in the data as delimited text, e.g. "admin|editor". It is not necessary to include the "authenticated user" role, as this is automatically maintained by core.

If desired, the module will send a welcome email to each new user. This uses the configurable template used by core for admin-created users.

Extensibility (Drupal 7 Only)

Note: Drupal 6 version users should refer to the module's README.txt file for instructions, as these notes apply only to the Drupal 7 version.

The UIF Plus module (http://drupal.org/project/uif_plus) provides support for import of additional fields such as entity reference fields, file and image fields, Profile2 fields, and OG.

If your needs go further, several hooks are provided so that you can import additional information. It is the developer's responsibility to write hook functions to do the work.

hook_uif_help()
This hook allows you to insert help text on the import page. The text appears beneath the basic help provided by the module.

hook_uif_validate_header($header)
Your module can implement this hook to validate the array of header values. You may require certain fields for your situation. This is the place to check if the column exists in the import file. Return an array of error strings, all of which will be displayed, and the user will not be allowed to do the import. An empty array (or NULL) is success.

hook_uif_validate_user($user_data, $uid)
This hook is called for every row of user data in the file. Like hook_uif_validate_header(), you can return any number of error strings, which are displayed to the user and which cause the import to fail. $user_data is an array of key => value pairs, where the key is the header column and the value is the data from the user row. All values are trimmed. $uid is either 0 for a new user or a positive integer for an existing user.

hook_uif_pre_create($account, $user_data)
This hook is called before a new user is created (before user_save() is called). $account contains basic account data (mail, name, pass). $user_data contains key => value pairs for the user about to be created. Function should return an array of values to add to $account.

hook_uif_post_create($account, $user_data)
This hook is called after a new user is created (after user_save() is called). Same arguments as hook_uif_pre_create().

hook_uif_pre_update($account, $user_data)
Same idea as hook_uif_pre_create(), but used for existing (updated) users. In this case, $account->uid will be a positive integer.

hook_uif_post_update($account, $user_data)
Same idea as hook_uif_post_create(), but used for existing (updated) users. In this case, $account->uid will be a positive integer.

Of course, since user_save() is called, core's hook_user() is available to you as well.

Additional Modules

Check out UIF for Organic Groups http://drupal.org/project/uif_og for support importing users to specific groups.

Code Examples

For additional code examples or to contribute your own, please visit http://drupal.org/node/1014688

Sponsor

This module is sponsored by the Human Capital Institute (http://www.hci.org).

Project Information

Downloads