diff --git a/README.md b/README.md index 1c3bfaf498364ba953089dafca8dea4435500dc0..9ca856bbd704d1b0b041734cf8f2d539e1232fc9 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,11 @@ Q: How should I update from Drupal 6? A: Run update.php; Enable the og-migrate module and execute all the migration plugins. +Q: How should I update from OG user roles D6? +A: Create a new variable named og_7000_access_field_default_value and set it to + FALSE, this will ensure that global roles are used (as in D6), You can later + modify each group to allow specific roles and permissions per group. + Q: How should I update from a previous Drupal 7 release (e.g. 7.x-1.0 to 7.x-1.1)? A: Same as updating from Drupal 6 -- Run update.php; If requested enable the diff --git a/includes/migrate/7000/og_ogur_roles.migrate.inc b/includes/migrate/7000/og_ogur_roles.migrate.inc index 33357dc2fbfcea0b350621237e73895a42e20c92..a57430273eeaa476f5f61a06862ea99bf54e7cb1 100644 --- a/includes/migrate/7000/og_ogur_roles.migrate.inc +++ b/includes/migrate/7000/og_ogur_roles.migrate.inc @@ -50,13 +50,34 @@ class OgMigrateOgurRoles extends MigrationBase { 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); + //Set og role id to the drupal id + $og_role->rid = $drupal_role; + // We cannot use og_role_save because we're inserting records with + // an existing rid already set. + if ($og_role->name) { + // Prevent leading and trailing spaces in role names. + $og_role->name = trim($og_role->name); + } + $status = drupal_write_record('og_role', $og_role); + module_invoke_all('og_role_insert', $og_role); + og_invalidate_cache(); + $roles[$role->rid] = $og_role->rid; } } } } + // This handles the migration of global permissions. + if (!variable_get('og_7000_access_field_default_value', TRUE)) { + // If we have global roles and permissions, we need to copy the current + // main permissions to OG roles. + $permissions = user_role_permissions($roles); + foreach ($roles as $drupal_rid => $og_rid) { + og_role_change_permissions($og_rid, $permissions[$drupal_rid]); + } + } + // Delete the field that indicates we still need to add fields. variable_del('og_7200_ogur_roles'); diff --git a/og_ui/includes/migrate/7000/populate_field.inc b/og_ui/includes/migrate/7000/populate_field.inc index 13ed128aae1900dfda7b447b452985fd4503bb81..5902f6c7ed7d6a0814166441a1de5a13cfe12387 100644 --- a/og_ui/includes/migrate/7000/populate_field.inc +++ b/og_ui/includes/migrate/7000/populate_field.inc @@ -41,7 +41,7 @@ class OgUiPopulateField extends DynamicMigration { $this->destination = new MigrateDestinationNode($bundle); $this->addFieldMapping('nid', 'nid'); - $this->addFieldMapping(OG_DEFAULT_ACCESS_FIELD, NULL)->defaultValue(TRUE); + $this->addFieldMapping(OG_DEFAULT_ACCESS_FIELD, NULL)->defaultValue((int) variable_get('og_7000_access_field_default_value', TRUE)); } /** diff --git a/og_ui/og_ui.module b/og_ui/og_ui.module index 665c9711d4bd7e5fe683a985146ae255e7f62cd3..c04cba7504288536a75254211eefc95dad712d82 100644 --- a/og_ui/og_ui.module +++ b/og_ui/og_ui.module @@ -1192,7 +1192,14 @@ function og_ui_migrate_api() { $migrations = array(); if (db_table_exists('d6_og')) { $migrations['OgUiMigrateAddField'] = array('class_name' => 'OgUiMigrateAddField'); - $migrations['OgUiSetRoles'] = array('class_name' => 'OgUiSetRoles'); + + // This handles the migration of permissions. + if (variable_get('og_7000_access_field_default_value', TRUE)) { + // If the default value of access in a group is per-group, migrate each + // group. Else, the global permissions have been already migrated in + // hook_update_7200. + $migrations['OgUiSetRoles'] = array('class_name' => 'OgUiSetRoles'); + } foreach (node_type_get_names() as $bundle => $value) { $machine_name = 'OgUiPopulateField' . ucfirst($bundle);