0

I imported an external database into my local Drupal database. The database table I am particularly interested in is the default "users" table in Drupal and the imported "USER" table from the imported database (My current Drupal database has both "users" and "USER" tables).

The external "USER" table contains columns that are not contained in my current Drupal "users" table.

I would like to perform either one of the following:

  1. Merge the "users" and the "USER" table, so that all the rows from the "USER" table is now contained in the "users" table.
  2. Allow Drupal to obtain login information from the externally imported "USER" table. By this, I mean if there is a user called "ABC" in the "USER" table, then Drupal should allow user ABC to log into the website.

Any help is appreciated. Thank you.

EDIT:

I have tried using the migrate module, but nothing shows up nor do any options show up for me to migrate my data. I have found a little tutorial that teaches how to import external data using drush and migrate - http://www.gizra.com/content/data-migration-part-1. Is this the correct way to use Migrate?

  • You haven't mentioned if you're using Drupal 6 or 7 from what I can see. In case you are using Drupal 7, you can add fields to users which Migrate integrates nicely with. And yes, you need to write code to use Migrate. It does nothing out of the box, it just gives you (very good) tools to import your data into Drupal. – Berdir Mar 14 '12 at 20:46
  • @Berdir. Thanks for the comment. I am using Drupal 7. Could you please provide me with a tutorial or some help in how to add extra columns/attributes/fields to the Drupal default "users" table? There are vital fields in the external table that need to be added to the "users" table. Thanks. – chlong Mar 15 '12 at 14:13
  • A quick google search turned up joedag32.com/2011/03/18/add-fields-to-user-in-drupal-7. It's easy, just go the page mentioned there and start adding stuff. Then you just need to tell Migrate into which field you want to import what. – Berdir Mar 15 '12 at 15:21
2

You have at least 2 choices, none of which is easy in my opinion.

  1. Import the non-drupal-users into drupal using a tool such as Migrate to actually map the new fields into drupal fields, you can use hook_schema_alter() and hook_entity_propery_info_alter() to tell Drupal about these new fields that Migrate is moving over.
  2. If you dont merge these tables permenantly into 1 drupal "users" table you're kinda making more trouble for yourself. You could implement your own authentication method to do an SQL query against your (non-drupal) Users table and if the visitor is found there create a new Drupal user account for them. To do so you'd basically create your own login logic as loosely described here for an external source, Blog Tutorial
  • Tenken, how can I add new fields in the external database "USER" table to Drupal's "users" table? – chlong Mar 14 '12 at 18:05
  • You can use Migrate to migrate individual fields from one table to another, or whole User rows if-needed. See the project page linked above. – tenken Mar 14 '12 at 18:24
  • Thanks for the recommendations tenken, would you also happen to know of a good tutorial that teaches how to use the Migrate module? – chlong Mar 14 '12 at 18:39
  • The migrate module itself comes with various examples reading data from a database table/rows as fake Beer and Wine company data. JSON files, XML files, CSV files ... there is also documentation linked the project page. – tenken Mar 14 '12 at 20:37

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.