summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-02-05 21:07:56 +0000
committerDries Buytaert <dries@buytaert.net>2010-02-05 21:07:56 +0000
commit06daeb7d505c7439fa4bf32c150561d7d1cbe8d3 (patch)
tree7cff79c06d571e52502d08f6a304e7fdf3e996dc
parent768b07978ca9dfd98ec0df0bc48bd4e33e4f292a (diff)
downloadbrdo-06daeb7d505c7439fa4bf32c150561d7d1cbe8d3.tar.gz
brdo-06daeb7d505c7439fa4bf32c150561d7d1cbe8d3.tar.bz2
- Patch #607238 by agentrickard: fixed user_modules_uninstalled() calling hook_permission() for already uninstalled modules.
-rw-r--r--modules/user/user.install32
-rw-r--r--modules/user/user.module33
2 files changed, 54 insertions, 11 deletions
diff --git a/modules/user/user.install b/modules/user/user.install
index d3d6f095a..d6357ed12 100644
--- a/modules/user/user.install
+++ b/modules/user/user.install
@@ -65,6 +65,13 @@ function user_schema() {
'default' => '',
'description' => 'A single permission granted to the role identified by rid.',
),
+ 'module' => array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'not null' => TRUE,
+ 'default' => '',
+ 'description' => "The module declaring the permission.",
+ ),
),
'primary key' => array('rid', 'permission'),
'indexes' => array(
@@ -490,3 +497,28 @@ function user_update_7005(&$sandbox) {
* The next series of updates should start at 8000.
*/
+/**
+ * Add module data to {role_permission}.
+ */
+function user_update_7006(&$sandbox) {
+ $module_field = array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'not null' => TRUE,
+ 'default' => '',
+ 'description' => "The module declaring the permission.",
+ );
+ // Check that the field hasn't been updated in an aborted run of this
+ // update.
+ if (!db_column_exists('role_permission', 'module')) {
+ // Add a new field for the fid.
+ db_add_field('role_permission', 'module', $module_field);
+ }
+ $permissions = user_permissions_get_modules();
+ foreach ($permissions as $key => $value) {
+ db_update('role_permission')
+ ->fields(array('module' => $value))
+ ->condition('permission', $key)
+ ->execute();
+ }
+}
diff --git a/modules/user/user.module b/modules/user/user.module
index ed9aa6bf0..01f2d3ff2 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -2534,6 +2534,23 @@ function user_role_delete($role) {
}
/**
+ * Determine the modules that permissions belong to.
+ *
+ * @return
+ * An associative array in the format $permission => $module.
+ */
+function user_permission_get_modules() {
+ $permissions = array();
+ foreach (module_implements('permission') as $module) {
+ $perms = module_invoke($module, 'permission');
+ foreach ($perms as $key => $value) {
+ $permissions[$key] = $module;
+ }
+ }
+ return $permissions;
+}
+
+/**
* Change permissions for a user role.
*
* This function may be used to grant and revoke multiple permissions at once.
@@ -2583,12 +2600,14 @@ function user_role_change_permissions($rid, array $permissions = array()) {
* @see user_role_revoke_permissions()
*/
function user_role_grant_permissions($rid, array $permissions = array()) {
+ $modules = user_permission_get_modules();
// Grant new permissions for the role.
foreach ($permissions as $name) {
db_merge('role_permission')
->key(array(
'rid' => $rid,
'permission' => $name,
+ 'module' => $modules[$name],
))
->execute();
}
@@ -3332,17 +3351,9 @@ function user_modules_installed($modules) {
* Implements hook_modules_uninstalled().
*/
function user_modules_uninstalled($modules) {
- $permissions = array();
- foreach ($modules as $module) {
- if (function_exists($module . '_permission')) {
- $permissions = array_merge($permissions, array_keys(module_invoke($module, 'permission')));
- }
- }
- if (!empty($permissions)) {
- db_delete('role_permission')
- ->condition('permission', $permissions, 'IN')
- ->execute();
- }
+ db_delete('role_permission')
+ ->condition('module', $modules, 'IN')
+ ->execute();
}
/**