Problem/Motivation

I have a need to run a bulk import where some users already exists and others don't. For the ones that exist, I'd like to update their information with what's in the spreadsheet, especially their roles.

Proposed resolution

I've posted a patch to get the ball rolling, and to see if this feature is OK to flesh out a little more. Below are the remaining tasks that could make this update more valuable.

Remaining tasks

  • Add a configuration option to allow/prevent existing users from being updated.
  • Combine the createUser() and updateUser() functions since there's a lot of overlap. A flag could be passed to the function to say if it's a "create" or "update".
  • Other requested updates, likely for other threads:
    • Incorporate /admin/config/people/bulk_user_register form into the /admin/people/bulk_user_register form
    • Add the /admin/people/bulk_user_register form to the administrative menu
    • There are some other updates that could be made for Drupal 9 compatibility (ex. user_load_by_mail)
    • Add a configuration option to explicitly allow/prevent user emails from sending after an account is created
    • Add a configuration option to customize the delimiter
    • Move the array of extra fields to include in the CSV out of hook_bulk_user_registration_extra_fields() and over to the configuration UI page

User interface changes

Comments

ryankavalsky created an issue. See original summary.

ryankavalsky’s picture

Here's the initial patch for review. Note: This patch applies to 8.x-1.x-dev, but you'll likely want to patch the newest release. See comment #3 below.

ryankavalsky’s picture

My apologies - that patch was applied against 8.x-1.x-dev. This patch works for the newest release, 8.x-1.1-beta1.

ryankavalsky’s picture

Issue summary: View changes
ryankavalsky’s picture

Issue summary: View changes
ryankavalsky’s picture

Does anybody know when this patch can be reviewed and merged?

sutharsan’s picture

I foresee that updating existing users can grow pretty complex from a UX point of view. What to do with existing data? Which fields to update and which not? Which field(s) to be the unique key? From a module maintenance point of view, I'd rather not go down this road.

richarddavies’s picture

Whoa, I've got a major case of déjà vu right now. I recently had the same need to update existing users with new roles and wrote a patch for this module to do that. I realized today I'd never submitted my patch and came here to do that. Imagine my surprise when I see that a new issue/patch now exists for that very same problem written about the same time as I was writing my patch!

Anyway, I'm going to add my +1 for this use case and include my patch for reference as well. As for the questions raised by Sutharsan, I took a very simple approach. It only allows updating the user's role (their username and email address are far less likely to ever change). You're already using the email address as the unique key to determine if a user already exists or not so I just used that same logic/key.

If we keep the scope limited to just updating roles, it doesn't really pose that many problems or challenges.

visway12’s picture

I faced same kind of problem and added this patch. Added a custom hook like presave and postsave which will be invoked when user already exist while import.

Refer: https://www.drupal.org/project/bulk_user_registration/issues/3487248