0

I'm using the Migrate module to migrate users from a non-Drupal PHP/MySQL site to Drupal 7. The users are spread across two tables, the second of which has a non-unique email column, many values of which are present in the first table.

Generally, how do I import the second table, inserting users with new email addresses, and updating a couple fields whenever the email address is already present among the users created from the first table and avoiding duplication errors from the second?

The users from the first table are administrators. The users in the second table are clients. There are other tables that references administrators and clients by ID. The ID columns for the two types of users are unique only within its respective table.

I made all the client uid's globally unique by adding 10,000 to all their uid's and updating their references in the other tables accordingly.

1

It depends on what kind of method, modules, tools you'd like to use to migrate the data as each of them might have their own settings for the kind of situation you had described.

If it's just a custom script migrating data between databases, then I would treat all users the same and import any of the tables first and then import the second one ignoring the error message - Drupal won't be importing users with the existing e-mail twice. After the migration you could go over each admin to assign appropriate role.

  • Thanks. I neglected to mention I'm using the Migrate module for the migration. I updated my question with that detail. – htoip Apr 2 '18 at 19:30
  • So how many admins you have? If not many, then why don't you migrate all the regular users first and deal with few admins manually? – AltaGrade Apr 2 '18 at 19:33
  • Well, they're actually pretty weak admins. There are about seven or eight thousand. – htoip Apr 2 '18 at 20:19
  • Wow, seven or eight thousand admins? Well, then you have to import admins first assigning admin roles to them and then only regular users, because Drupal should reject registering users with already existing e-mails. – AltaGrade Apr 2 '18 at 22:48
  • I suspect a huge number of them are either spammers or testers, but I can't be sure. I haven't found a way to do this with Migrate yet, so I wrote a script to look at each client, if the client email matches an admin email then change the uid to match too. Next I'll write a script to add the client role to all the admins that are also in the client table. When that's done I'll run Migrate on the clients; the new ones will be imported; the duplicates will error out. – htoip Apr 3 '18 at 0:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.