Closed (fixed)
Project:
Drupal-to-Drupal data migration
Version:
7.x-2.0-rc1
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
20 Oct 2012 at 04:21 UTC
Updated:
6 Nov 2012 at 15:00 UTC
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
Comment #1
mikeryanYes, 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:
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.
Comment #2
mixhael commentedThanks,
In my case there is already an existing destination-role called 'editor' and a source role called 'Editor' (capital E)
Is it case-sensitive?
Comment #3
mixhael commentedThanks,
In my case there is already an existing destination-role called 'editor' and a source role called 'Editor' (capital E)
Is it case-sensitive?
Comment #4
mikeryanThe comparison is case-insensitive, but for documentation purposes I would use the exact cases in the role_mapping.
Comment #5
peteruithoven commentedTip: 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?
Comment #6
mixhael commentedthanks a lot
Comment #7.0
(not verified) commentedmade some info more specific