Posted by ajayg on May 3, 2009 at 4:19pm
6 followers
| 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
#5
Here's a patch against CVS HEAD which allows a field from the CSV file to be mapped to $user['create']
#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.
#7
I have this same requirement, plus support for migrating:
Attached patch does this, needs fully testing.
Happy to put this into another issue if required.
#8
#9
#10
Nice patch boxfresh! It works fine.
Since I'm importing users from an external source, I like the
strtotime()use intouser_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()