From c4bc14ed7e6004ef7e31aea1175d1e58f740dcb7 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 7 Mar 2013 04:30:34 -0500 Subject: [PATCH] CRM-11925 - Loosen coupling between permission enumeration (getModulePermissions) and storage (upgradePermissions) --- CRM/Core/Config.php | 5 ++++- CRM/Core/Permission/Base.php | 6 +++++- CRM/Core/Permission/Drupal.php | 9 +++------ CRM/Core/Permission/Drupal6.php | 7 ++----- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/CRM/Core/Config.php b/CRM/Core/Config.php index ccea740ce2..875b67994b 100644 --- a/CRM/Core/Config.php +++ b/CRM/Core/Config.php @@ -662,7 +662,10 @@ class CRM_Core_Config extends CRM_Core_Config_Variables { foreach ($module_files as $module_file) { // Clean up old module permissions that have been removed in the current // module version. - $this->userPermissionClass->upgradePermissions($module_file['prefix']); + $this->userPermissionClass->upgradePermissions( + $module_file['prefix'], + $this->userPermissionClass->getModulePermissions($module_file['prefix']) + ); } } diff --git a/CRM/Core/Permission/Base.php b/CRM/Core/Permission/Base.php index e606398ec1..5f222a8f5a 100644 --- a/CRM/Core/Permission/Base.php +++ b/CRM/Core/Permission/Base.php @@ -163,8 +163,12 @@ class CRM_Core_Permission_Base { * actually defined by that module. This is useful during module upgrade * when the newer module version has removed permission that were defined * in the older version. + * + * @param string $module short-name + * @param array $modulePermissions same format as CRM_Core_Permission::getCorePermissions(). + * @see CRM_Core_Permission::getCorePermissions */ - function upgradePermissions($module) { + function upgradePermissions($module, $modulePermissions) { } /** diff --git a/CRM/Core/Permission/Drupal.php b/CRM/Core/Permission/Drupal.php index 74b25e3caf..f2b9a0c657 100644 --- a/CRM/Core/Permission/Drupal.php +++ b/CRM/Core/Permission/Drupal.php @@ -95,15 +95,12 @@ class CRM_Core_Permission_Drupal extends CRM_Core_Permission_DrupalBase{ } /** - * Ensure that all cached permissions associated with the given module are - * actually defined by that module. This is useful during module upgrade - * when the newer module version has removed permission that were defined - * in the older version. + * {@inheritdoc} */ - function upgradePermissions($module) { + function upgradePermissions($module, $modulePermissions) { $config = CRM_Core_Config::singleton(); // Get all permissions defined by the module. - $module_permissions = self::filterPermissions($config->userPermissionClass->getModulePermissions($module), $module); + $module_permissions = self::filterPermissions($modulePermissions, $module); // Construct a delete query to remove permissions for this module. $query = db_delete('role_permission') ->condition('permission', "$module|%", 'LIKE') diff --git a/CRM/Core/Permission/Drupal6.php b/CRM/Core/Permission/Drupal6.php index cc7dbaca1c..353da32ad0 100644 --- a/CRM/Core/Permission/Drupal6.php +++ b/CRM/Core/Permission/Drupal6.php @@ -158,14 +158,11 @@ class CRM_Core_Permission_Drupal6 extends CRM_Core_Permission_DrupalBase { } /** - * Ensure that all cached permissions associated with the given module are - * actually defined by that module. This is useful during module upgrade - * when the newer module version has removed permission that were defined - * in the older version. + * {@inheritdoc} * * Does nothing in Drupal 6. */ - function upgradePermissions($module) { + function upgradePermissions($module, $modulePermissions) { } /** -- 2.25.1