I noticed that when importing my users, their roles were not automatically imported. Then I started inspecting the code and noticed this ' if ($this->roleMigration)' statement in the DrupalUserMigration class:

// Populate the source roles
    if ($this->roleMigration) {
      $result = Database::getConnection('default', $this->sourceConnection)
                ->select('users_roles', 'ur')
                ->fields('ur', array('rid'))
                ->condition('uid', $row->uid)
                ->execute();
      foreach ($result as $role_row) {
        $row->roles[] = $role_row->rid;
      }
    }

Does that mean that you have to create a separate RoleMigration first and then provide its machine name to the user migration with '$arguments['role_migration']'?

Then also a question about rolemigration: I noticed the '$this->roleMappings = $arguments['role_mappings']' statement and how this is used in the prepareRow() function. Can you tell me more on it's workings and give a simple example on how to use it?

Comments

mikeryan’s picture

Status: Active » Fixed

Yes, just instantiate the DrupalRole6Migration class and reference it's machine name as role_migration.

The role_mappings let you map a Drupal 6 role name to a Drupal 7 role name. For example, with some recent migrations I've been working on, the destination Drupal 7 site has a role 'fan club member', while the Drupal 6 sites have named the equivalent role various other things, such as 'Fan Club'. Also, we want the Drupal 6 role Site Admin mapped to Drupal 7 role administrator. So:

$arguments['role_mappings'] = array(
      'Fan Club' => 'fan club member',
      'Site Admin' => 'administrator',
    );

When DrupalRole6Migration imports, when it sees Fan Club instead of creating a new role of that name it will put a row in the map table with the role ID of 'fan club member' as destid1. Then, when the user migration runs, when the Fan Club rid is assigned in the source data, the rid of 'fan club member' will be assigned. Any roles not listed in role_mappings will be imported in the usual way.

mixhael’s picture

Status: Fixed » Active

Thanks,

In my case there is already an existing destination-role called 'editor' and a source role called 'Editor' (capital E)

Is it case-sensitive?

mixhael’s picture

Thanks,

In my case there is already an existing destination-role called 'editor' and a source role called 'Editor' (capital E)

Is it case-sensitive?

mikeryan’s picture

Status: Active » Fixed

The comparison is case-insensitive, but for documentation purposes I would use the exact cases in the role_mapping.

peteruithoven’s picture

Tip: you can find the role names of a D6 or D7 website in the "role" table in the database.
Would it be weird to list them somewhere in the migration interface?

mixhael’s picture

thanks a lot

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

made some info more specific