Commit 201611fd authored by SebCorbin's avatar SebCorbin Committed by amitaibu

Issue #1565546 by SebCorbin, pgillis: OG User Roles (OGUR) upgrade path

parent b9bbc3a8
<?php
/**
* @file
* Migrate OGUR(6.x) roles and relations to 7.x-2.x.
*/
class OgMigrateOgur extends Migration {
/**
* Override constructor from Migration class.
*/
public function __construct() {
parent::__construct();
$this->description = t('Migrate OGUR content from 6 to 7.x-2.x.');
$this->dependencies[] = 'OgMigrateOgurRoles';
$this->dependencies[] = 'OgMigrateUser';
$this->query = db_select('d6_og_users_roles', 'ogur');
$this->query->join('role', 'r', 'ogur.rid = r.rid');
$this->query->join('og_role', 'ogr', 'r.name = ogr.name');
$this->query->fields('ogur', array('gid', 'uid'))
->fields('ogr', array('rid'));
$source_key = array(
'gid' => array(
'alias' => 'ogur',
'type' => 'int',
'not null' => TRUE,
'description' => 'node ID of group.',
),
'uid' => array(
'alias' => 'ogur',
'type' => 'int',
'not null' => TRUE,
'description' => 'User ID of member.',
),
'rid' => array(
'alias' => 'ogr',
'type' => 'int',
'not null' => TRUE,
'description' => 'Role ID of role.',
),
);
$this->map = new MigrateSQLMap($this->machineName, $source_key, MigrateDestinationTable::getKeySchema('og_users_roles'));
$this->source = new MigrateSourceSQL($this->query);
$this->destination = new MigrateDestinationTable('og_users_roles');
$field_names = array(
'gid',
'uid',
'rid',
);
foreach ($field_names as $field_name) {
$this->addFieldMapping($field_name, $field_name);
}
$this->addFieldMapping('group_type', NULL)->defaultValue('node');
}
}
<?php
/**
* @file
* Add OG related fields to group and group-content node-types.
*/
class OgMigrateOgurRoles extends MigrationBase {
/**
* Override constructor from Migration class.
*/
public function __construct() {
parent::__construct();
$this->description = t('Create OG Roles for OGUR roles from system role table.');
$this->enabled = !$this->isComplete();
$this->dependencies[] = 'OgMigrateAddFields';
}
/**
* Check variable to see if we have already run this job.
*
* @return bool
* TRUE if we have already completed.
*/
public function isComplete() {
return !variable_get('og_7200_ogur_roles', FALSE);
}
/**
* Create group, group-audience and group description fields.
*/
public function import() {
// We are only interested in roles actually managed by OGUR, not default.
$og_roles = array();
foreach (node_type_get_types() as $type) {
$og_roles[$type->type] = variable_get('og_user_roles_roles_' . $type->type);
}
$roles = array();
$drupal_roles = db_select('d6_og_users_roles', 'ogur')
->fields('ogur', array('rid'))
->groupBy('rid')
->orderBy('rid', 'ASC')
->execute()
->fetchCol();
// For each role, enumerate over all possible types and respective bundles.
foreach ($drupal_roles as $drupal_role) {
foreach (og_get_all_group_bundle() as $type => $bundle_array) {
foreach ($bundle_array as $bundle => $name) {
if ($og_roles[$bundle][$drupal_role]) {
$role = user_role_load($drupal_role);
$og_role = og_role_create($role->name, $type, 0, $bundle);
og_role_save($og_role);
$roles[$role->rid] = $og_role->rid;
}
}
}
}
// Delete the field that indicates we still need to add fields.
variable_del('og_7200_ogur_roles');
return MigrationBase::RESULT_COMPLETED;
}
}
......@@ -47,6 +47,10 @@ files[] = includes/migrate/7000/og_content.inc
files[] = includes/migrate/7000/og_group.inc
files[] = includes/migrate/7000/og_user.inc
; Migrate OGUR data from 6.x to 7.x-2.x
files[] = includes/migrate/OGUR_6000-7200/og_ogur_roles.migrate.inc
files[] = includes/migrate/OGUR_6000-7200/og_ogur.migrate.inc
; Migrate from 7.x-1.x to 7.x-2.x
files[] = includes/migrate/og.migrate.inc
files[] = includes/migrate/7200/og_og_membership.migrate.inc
......
......@@ -1020,6 +1020,9 @@ function og_update_7200() {
// See http://drupal.org/node/996236
entity_info_cache_clear();
// Temporary variable to indicate we need to migrate OGUR data.
variable_set('og_7200_ogur_roles', TRUE);
return t('Enable "Migrate-UI" module to continue the migration of data. Once migration is done you may disable "Migrate" module');
}
......
......@@ -3550,6 +3550,12 @@ function og_migrate_api() {
'bundle' => $bundle,
);
}
if (db_table_exists('d6_og_users_roles')) {
// OG user roles (OGUR) related migrations.
$migrations['OgMigrateOgurRoles'] = array('class_name' => 'OgMigrateOgurRoles');
$migrations['OgMigrateOgur'] = array('class_name' => 'OgMigrateOgur');
}
}
elseif (db_field_exists('og_membership', 'group_type') && db_table_exists('og') && !db_table_exists('d6_og')) {
$migrations['OgMigrateMembership'] = array('class_name' => 'OgMigrateMembership');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment