0

I want to migrate an old website (not Drupal) into Drupal. I want to migrate a table to a specific content type...

Inside that table there are many fields in addition to the user_id field, so every record has 'field_1', 'field_2', ..., 'field_n' and 'user_id' field (foreign key of table "users")

First I successfully migrated "users" table. The problem is that 'user_id' ( of old website) is not the same as 'uid' of the Drupal website. For example assuming that the first record will be migrated, has the 'user_id' = 255. This user is already inserted with the 'uid' = 55 inside Drupal. Now I want to insert the node with the correct uid (witch is 55), but inside the table I have 255.

How can I do the correct mapping inside the Migrate class to insert every record inside "node" table with the correct 'uid' ? Or if there is another solution to do it "All in one" (create users and the nodes at the same time) maybe Migrate module has some powerfull functionality like creating a temporary database table that tell the migrate classes that the uid 55 is the same as the user_id 255 of the old website...

Thanks in advance.

  • 1
    Migrate module does take care of this problem. It will maintain a mapping between the old and new IDs. – Aaron Aug 21 '15 at 12:43
2

You use the sourceMigration() method of the migrate module. You should:

1) Write one migration to migrate old users to the new version of drupal. 2) Then write a migration that moves an old table to the new version of drupal.

In (2) when you setup your field migration it sounds like you've written:

# Field Mappings Docs: https://www.drupal.org/node/1133448
# this maps new <= old field.
$this->addFieldMapping('new_user_id_field', 'old_user_id_field');

When you want to write:

# Search for sourceMigration on this page:
# https://www.drupal.org/node/1133448
$this->addFieldMapping('new_user_id_field', 'old_user_id_field')->sourceMigration('MigrateLegacyUsers');

This then uses a previously run MigrateLegacyUsers migration I described in (1) as the lookup for the new user ID in the new drupal site from the mapping table stored by Migrate for the old_user_id_field created during the MigrateLegacyUsers migration task.

Also note if you possibly have multiple users migrated into the system, say from a drupal legacy system, a wordpress system or LDAP you could write:

`->sourceMigration(array('MigrateLegacyUsers', 'MigrateWordressUsers', 'MigrateLDAPUsers'));`

This means: Find the legacy user id among all these possible prior migrations of Users. The first user_id that matches the requested legacy ID will be used by migrate (so be careful to assure all the user_ids are unique across multiple sources).

  • the key of the problem is "->sourceMigration". thanks a lot. – Boussetta moez Aug 23 '15 at 13:54

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.