Download & Extend

preserving registration time, last login, last access, language and timezone

Project:User Import
Version:6.x-2.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review

Issue Summary

If I need to preserve registration time could you please give some hints where I would set those?
I am asking hints for changes in code as I know it is not a feature yet supported by user_import

Comments

#1

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.

#2

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.

#3

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.

#4

Status:active» needs review

#5

Version:5.x-2.8» master

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

AttachmentSize
user_created_date.patch 2.27 KB

#6

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.

AttachmentSize
user_created_date-2.patch 2.43 KB

#7

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.

AttachmentSize
include_date_timezone_fields.patch 1.78 KB

#8

Title:preserving registration time» preserving registration time, last login, last access, language and timezone
Category:support request» feature request

#9

Version:master» 6.x-2.x-dev

#10

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.

#11

Subscribing.

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

#12

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:

<?php
/**
* 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;
}
?>

#13

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()