0

I'm creating a Migration from our old website (non-Drupal) to our new Drupal website. On our old website, roles and role assignments were kept in 2 seperate tables. So far, I've written a simple UserMigration and a RoleMigration class. However, I'm in doubt how I should proceed for the RoleMembershipMigration.

In short: Should I manually load roles in a prepare function for the UserMigration, or should this be done in a seperate Migration class altogether? I'm inclined towards the first, since it is not actually a migration to a seperate entity.

0

I suggest to join roles and role assignements tables togother in your query of RoleMigration class, in that case you will have these fields as source fields : role_id, user_id, role_name

now in UserMigration you just need to apply the dependency of the role migration on "roles" field :

$this->addFieldMapping('roles', 'role_name')
            ->sourceMigration('Role')
            ->defaultValue(drupal_map_assoc(array(2))); // authenticated user default value

Don't forget also that the key field of migration mapping should be the user_id field :

$this->map = new MigrateSQLMap($this->machineName,
        array('user_id' => array(
                'type' => 'int',
                'not null' => TRUE,
                'description' => 'User ID.'
                )
            ),
        MigrateDestinationUser::getKeySchema()
    );

Didn't test it but should work like that!

| 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.