You are here

public function OgMigrateUserRoles::prepare in Organic groups 7.2

File

includes/migrate/7200/og_user_roles.migrate.inc, line 67
Update the group ID in user roles.

Class

OgMigrateUserRoles
@file Update the group ID in user roles.

Code

public function prepare($entity, $row) {
  $group_type = $row->group_type;
  $gid = $row->gid;
  if (!($group = entity_load_single($group_type, $gid))) {

    // Some installations might have missing entities, so we don't assume
    // they exist.
    return;
  }

  // Get the bundle from the entity.
  list(, , $bundle) = entity_extract_ids($group_type, $group);

  // Get the per-bundle roles, and replace the role ID, with the
  // per-bundle role ID.
  $og_roles = og_roles($group_type, $bundle, $gid);
  if (!empty($this->defaultRoles[$row->rid]) && ($rid = array_search($this->defaultRoles[$row->rid], $og_roles))) {

    // Assign the new role ID.
    $entity->rid = $rid;
  }
  $entity->group_type = $row->group_type;
  $entity->gid = $row->gid;
}