1

We have an existing Drupal site that has a requirement to inherit about 10k users into, and we've been able to gather most of this data through CSV exports on the Database, and Views Export/VBO. What we have is two CSVs, one with usernames, password hashes, UIDs; the other with user field data and a UID to join/union the data during import. There are differences between the Field structure between the site data we inherited and the new site, so new data relationships will need to be established during the import, ruling out a direct port of the existing Database records.

I have no issues writing a Drush script that will import all the users with a joined CSV. What I am wondering is if its possible to import the user records, complete with the password strings within the Drupal User space. Looking at the user_save() method its not clear as if I can define the User ID, or password hash. And we have a lot of logic implemented that depends upon this

So the approach I have in my head is this:

  • Use SQL IN FILE to import the baseline minimum data to establish users in Drupal's users table: Username, Password Hash, created date, changed date, etc...
  • Use a second drush script to iterate through the field data, and update the user records with user_save() off UID.

Is there another approach I can use that's strictly Drush based? This assumes that the data I import will be with a Unioned CSV file. Not being able to adjust the UID probably means this isn't possible, but its worth asking.

  • 1
    I don't think that you could create new users with a specific UID. What you could do, however, is to create a new integer field to hold a user's old UID and use this field as reference to implement other functionalities that depend on the old UID. Or better, you can then write another script to update those functionalities so that they respect the new UID instead of the old one, then you can delete this old UID field. – Елин Й. Jan 7 '15 at 17:41
2

It sounds like you're after the Feeds module! It supports mapping fields sources to destinations, and will auto-create entities in some cases.

After installing & enabling the module, you'll want to create a Feeds Importer (under Structure) and go from there. Navigate to /import to upload a CSV file to a feeds importer for processing.

There's a sandbox module Drush Feeds Import that should allow you to run some of this from the command line if necessary.

Check out:

The site builder's guide to Feeds:

https://www.drupal.org/node/622698

If the stock Feeds modules don't quite solve your problem, you could use the Feeds API to define your own processing class that manipulates and inserts the data into the new site.

| improve this answer | |

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.