It would be good to add support for importing data into all columns of the users db table.

The module is not really useful for drupal to drupal imports otherwise.

This is important becase a common use case is importing users from an existing drupal site, from the same or a different major version.

The fields are:

  • uid (this one is a bit different to the others but for the sake of data migration it should be possible)
  • theme
  • signature
  • signature_format
  • created
  • access
  • login
  • status
  • timezone
  • language
  • picture
  • init
  • data

Comments

ajayg’s picture

Ok so far I figured I need to add following to user_user_import_pre_save function in the case UPDATE_REPLACE section.

$account_add['created'] = "SOMETHING";

"SOMETHING" needs to be an integer (seconds since epoch) to represent when the account was created. However I don't know how to get the value of the field from imported file. In otherwords if there a column #6 called ctime which has this value how do i get inside user_user_import_pre_save function? I already tried

$account_add['created'] = $fields['user']['ctime'];

with no luck. ctime column is integer so $fields['user']['ctime'][0] won't work.

I am trying to import user list exported from discusware databse into drupal.

ajayg’s picture

I think I made further progress but still no luck
I modifiled function user_user_import_form_field_match inside supported/user.inc and added
$options['user']['created'] = t('Created on*');

This allowed me a new option to show up "Created on*"under field_match. That I matched up with csv field column.
And I also Changed the above line (first comment) so that "SOMETHING" becomes $fields['user']['created']

$account_add['created'] = $fields['user']['created'];

Still no luck.

ajayg’s picture

Ok I finally figured this out.

1. Modify function user_user_import_form_field_match inside supported/user.inc. Add

$options['user']['created'] = t('Created on*');

This will show the option to map registration (account creation) date to field in CSV file.

2. Modify function user_user_import_data inside supported/user.inc and Add

if ($field_id == 'created') {
    $value = trim($data[$column_id]);
  }

just before return $value. This will make sure the value is read from csv file and available for processing.

3. Add following to user_user_import_pre_save function in the case: UPDATE_REPLACE section (file :supported/user.inc )

$account_add['created'] = $fields['user']['created'][0];

When you create the template make sure you have a mapping created for 'Created on" field.

This will import the registration date.

ajayg’s picture

Status: Active » Needs review
nemchenk’s picture

Version: 5.x-2.8 » master
StatusFileSize
new2.27 KB

Here's a patch against CVS HEAD which allows a field from the CSV file to be mapped to $user['create']

nemchenk’s picture

StatusFileSize
new2.43 KB

A slightly better patch, again against HEAD. Now assumes the dates will be coming in as a timestamp, and also sets the creation date to time() as a default.

rsaddington’s picture

StatusFileSize
new1.78 KB

I have this same requirement, plus support for migrating:

  • last login
  • last access
  • language
  • timezone

Attached patch does this, needs fully testing.

Happy to put this into another issue if required.

rsaddington’s picture

Title: preserving registration time » preserving registration time, last login, last access, language and timezone
Category: support » feature
rsaddington’s picture

Version: master » 6.x-2.x-dev
chirale’s picture

Nice patch boxfresh! It works fine.

Since I'm importing users from an external source, I like the strtotime() use into user_created_date.patch (first patch) instead of simple assuming that date is specified in unix timestamp (drupal-to-drupal).

Is it possible to preserve both using two different options like Date created (as timestamp) and Date created (as string)? This could be useful even on Drupal, if users are exported from a view that expose dates as strings.

cyberwolf’s picture

Subscribing.

The language option was actually asked before in 2007, see #107500: Language Support. Nice to see a patch finally!

ryan_courtnage’s picture

I do think that adding support for user language and timezone to user_import makes perfect sense (and the patch in #7 works, thanks!). "Last access" and "Last login" perhaps satisfy a little bit more of an edge case.

FYI - For those wishing to add something that user_import doesn't support natively , you can implement it's hooks from a custom module. For example, the following would add support for language to vanilla user_import.module:


/**
 * Implementation of hook_user_import_form_field_match().
 */
function mymodule_user_import_form_field_match() {
  $options['user']['language'] = t('Language');
  return $options;
}

/**
 * Implementation of hook_user_import_data().
 */
function mymodule_user_import_data($settings, $update_setting, $column_settings, $module, $field_id, $data, $column_id) {
  if ($module != 'user') return;
  if ($field_id == 'language') {
    $value = trim($data[$column_id]);
  }
  return $value;
}

/**
 * Implementation of hook_user_import_pre_save().
 */
function mymodule_user_import_pre_save($settings, $account, $fields, $errors, $update_setting_per_module) {
  $account_add['language'] = $fields['user']['language'][0];
  return $account_add;
}

ryan_courtnage’s picture

Also required if you are trying to send notification emails in the user's preferred language:

#1267352: Not passing message['language'] to _user_mail_text()

rooby’s picture

Title: preserving registration time, last login, last access, language and timezone » Allowing import of system fields (created, access, login, status, language, timezone, init, data, etc.)
Version: 6.x-2.x-dev » 7.x-1.x-dev
Status: Needs review » Active

Since there has been no action for so long, changing to D7 and updating the original post.
It can be backported later.

We should account for all the columns in the users database table. The module is not useful for drupal to drupal imports otherwise.

For example, look at the fields that can be exported from the Profile CSV.

This is important becase a common use case is importing users from an existing drupal site, from the same or a different major version.

rooby’s picture

Issue summary: View changes

Adding a more detailed description of what the issue is actually about.

schifazl’s picture

Issue summary: View changes

I'm really interested in this functionality, especially for the user's language!

abaier’s picture

I would be interested in the status of this issue. Will development for d7 go on or are there any plans of porting this to d8?

Thanks in advance.

abaier’s picture

I tried the solution for language integration mentioned in #12 and it seems to work well.

The only thing is that I get the following watchdog messages:

Notice: Undefined variable: value in pso_custom_user_import_data() (Zeile 17 von /Applications/MAMP/htdocs/pso_git/htdocs/sites/all/modules/custom/pso_custom/pso_custom.module).

Notice: Undefined variable: value in user_user_import_data() (Zeile 96 von /Applications/MAMP/htdocs/pso_git/htdocs/sites/all/modules/user_import/supported/user.inc).

Does anybody know where to look for a fix? Unfortunately this would go to far for my php skills.

Thanks in advance for any help!