Skip to content
Snippets Groups Projects
Commit 78da0c89 authored by Qiangjun Ran's avatar Qiangjun Ran Committed by Qiangjun Ran
Browse files

Issue #3317718 by jungle: Implement hook_update_N() to update realms and...

Issue #3317718 by jungle: Implement hook_update_N() to update realms and migrate nodeaccess.settings
parent ef8cd85e
Branches
Tags
1 merge request!11Issue #3408893 by BenStallings: Explain how to find which gids go with which user roles.
......@@ -125,3 +125,89 @@ function nodeaccess_update_8101() {
$config->set('role_alias', $role_alias);
$config->save();
}
/**
* Updates realms.
*/
function nodeaccess_update_9001(&$sandbox) {
$database = \Drupal::database();
$database->update('nodeaccess')
->fields([
'realm' => 'nodeaccess_user',
])
->condition('realm', 'nodeaccess_uid')
->execute();
$database->update('nodeaccess')
->fields([
'realm' => 'nodeaccess_role',
])
->condition('realm', 'nodeaccess_rid')
->execute();
}
/**
* Migrates nodeaccess.settings.
*/
function nodeaccess_update_9002(&$sandbox) {
$config = \Drupal::configFactory()->getEditable('nodeaccess.settings');
// From grants to allowed_grant_operations.
$old_grants = $config->get('grants');
$config
->set('allowed_grant_operations', [
'grant_view' => (boolean) $old_grants['view'],
'grant_update' => (boolean) $old_grants['edit'],
'grant_delete' => (boolean) $old_grants['delete'],
])
->clear('grants');
// From allowed_types to grants_tab_availability.
$old_allowed_types = $config->get('allowed_types');
$grants_tab_availability = [];
foreach ($old_allowed_types as $bundle => $value) {
$grants_tab_availability[$bundle] = (boolean) $value;
}
$config
->set('grants_tab_availability', $grants_tab_availability)
->clear('allowed_types');
// From role_map to map_rid_gid.
$old_role_map = $config->get('role_map');
$config
->set('map_rid_gid', $old_role_map)
->clear('role_map');
// From role_alias to roles_settings.
$old_role_alias = $config->get('role_alias');
$roles_settings = [];
foreach ($old_role_alias as $role_id => $value) {
$roles_settings[$role_id] = [
'display_name' => $value['alias'],
'name' => $value['name'],
'weight' => (int) $value['weight'],
'selected' => (boolean) $value['allow'],
];
}
$config
->set('roles_settings', $roles_settings)
->clear('role_alias');
$bundles = array_keys($old_allowed_types);
$bundles_roles_grants = [];
foreach ($bundles as $bundle) {
$old_bundle_settings = $config->get($bundle);
foreach ($old_bundle_settings as $role_id => $grant) {
$bundles_roles_grants[$bundle][$role_id] = [
'grant_view' => (int) $grant['grant_view'],
'grant_update' => (int) $grant['grant_update'],
'grant_delete' => (int) $grant['grant_delete'],
];
}
$config->clear($bundle);
}
$config
->set('bundles_roles_grants', $bundles_roles_grants)
->clear('priority')
->clear('preserve')
->save();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment