I need the ability to only update existing users without creating new users. I accomplish this by commenting out the following code in user_import.module:
else {
// Only set a user name if we are not updating an existing record.
$account['name'] = _user_import_create_username($username_order, $username_data, $username_abbreviate, $settings['username_space']);
$password = $account['pass'];
$account = user_save('', $account);
}
My feature request is to have a setting that controls whether this code is executed (whether new users should be created).
Comments
Comment #1
cedarm commentedI agree, this should be part of User Import. Here's a patch against 6.x-1.2. It adds a checkbox to the Update Existing Users fieldset which enables this option. There's some slight restructuring of $form['update_user'], but the submitted form values should be unaffected. It also adds a 'skipped' counter for the rows that are skipped due to this option. This requires a database update (new column in {user_import} table) and various obvious changes to support the new column.
If this is not the approach the module maintainers want to take, it should be fairly easy to create an additional module to implement this feature. It would simply need to throws errors for the rows without an existing user. Not quite as elegant as the skipped counter, but it works.
Comment #2
sadist commentedthe patch is working great (though this is very old)
but can you help me, how if I want it to only skip creating a new user if username or email address already exist? but create the user if none exist.
Comment #3
cedarm commentedI haven't used user_import since then, but have used the migrate module. If migrate will meet your needs, consider using it instead. Any username or email address that already exists will just fail to create a duplicate account.
Comment #4
sadist commentedThanks, I'm not able to use migrate.module (dbtng threw me alot of error messages), but I tried using node_import.module instead. Now, I need to look for a way to import the users' registered date. Any idea?
Comment #5
cedarm commented(You should be requesting assistance in a new issue.)
So, that would be $account->created right? I think you can create a module and implement hook_user_import_pre_save(), or quick and dirty just modify user_user_import_pre_save(). Not sure if your source data field will be available automatically or not. Can' t dig in right now. Looking at my old code, for an arbitrary user property, I implemented hook_user_import_form_update_user(), hook_user_import_form_field_match(), and hook_user_import_data(), but that's in my D6 code. HTH.
Comment #6
sadist commentedI'd just posted my issue here #1013292: Users' Registered Date. Hope you can help me with some simple questions? Thanks.
Comment #7
victoriachan commentedI've created a patch for 6.x-4.1 to add a 'Skip new users' option. If selected, only existing user records will be updated, and new users will not be created. It is a lightweight change, with the option added as one of the import options such as 'Ignore First Line'.