function system_update_7007 in Drupal 7
Convert to new method of storing permissions.
Related topics
File
- modules/
system/ system.install, line 2026 - Install, update and uninstall functions for the system module.
Code
function system_update_7007() {
// Copy the permissions from the old {permission} table to the new {role_permission} table.
$messages = array();
$result = db_query("SELECT rid, perm FROM {permission} ORDER BY rid ASC");
$query = db_insert('role_permission')
->fields(array(
'rid',
'permission',
));
foreach ($result as $role) {
foreach (array_unique(explode(', ', $role->perm)) as $perm) {
$query
->values(array(
'rid' => $role->rid,
'permission' => $perm,
));
}
$messages[] = t('Inserted into {role_permission} the permissions for role ID !id', array(
'!id' => $role->rid,
));
}
$query
->execute();
db_drop_table('permission');
return implode(', ', $messages);
}