From 7fccad46422bff5262a6e0e66c9641d011f53382 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 7 Mar 2013 04:53:21 -0500 Subject: [PATCH] CRM-11925 - Only run cleanupPermissions/uninstallPermissions if our CMS driver supports it --- CRM/Core/Config.php | 35 +++++++++++++++++++++++++------- CRM/Core/Permission/Base.php | 13 ++++++++++++ CRM/Core/Permission/Drupal.php | 7 +++++++ CRM/Extension/Manager/Module.php | 4 +++- 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/CRM/Core/Config.php b/CRM/Core/Config.php index 875b67994b..aa45c82ec9 100644 --- a/CRM/Core/Config.php +++ b/CRM/Core/Config.php @@ -659,13 +659,34 @@ class CRM_Core_Config extends CRM_Core_Config_Variables { */ function cleanupPermissions() { $module_files = CRM_Extension_System::singleton()->getMapper()->getActiveModuleFiles(); - 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->getModulePermissions($module_file['prefix']) - ); + if ($this->userPermissionClass->isModulePermissionSupported()) { + // Can store permissions -- so do it! + foreach ($module_files as $module_file) { + // Consider corner case: Cleaning up old module permissions that have been removed + // by unversioned source-code changes. + $this->userPermissionClass->upgradePermissions( + $module_file['prefix'], + $this->userPermissionClass->getModulePermissions($module_file['prefix']) + ); + } + } else { + // Cannot store permissions -- warn if any modules require them + $modules_with_perms = array(); + foreach ($module_files as $module_file) { + $perms = $this->userPermissionClass->getModulePermissions($module_file['prefix']); + if (!empty($perms)) { + $modules_with_perms[] = $module_file['prefix']; + } + } + if (!empty($modules_with_perms)) { + CRM_Core_Session::setStatus( + ts('Some modules define permissions, but the CMS cannot store them: %1', array( + array(1 => implode(', ', $modules_with_perms)) + )), + ts('Permission Error'), + 'error' + ); + } } } diff --git a/CRM/Core/Permission/Base.php b/CRM/Core/Permission/Base.php index 5f222a8f5a..68bef77ce9 100644 --- a/CRM/Core/Permission/Base.php +++ b/CRM/Core/Permission/Base.php @@ -152,10 +152,22 @@ class CRM_Core_Permission_Base { CRM_Core_Error::fatal("this function only works in Drupal 6 at the moment"); } + /** + * Determine whether the permission store allows us to store + * a list of permissions generated dynamically (eg by + * hook_civicrm_permissions.) + * + * @return bool + */ + public function isModulePermissionSupported() { + return FALSE; + } + /** * Remove all vestiges of permissions for the given module. */ function uninstallPermissions($module) { + throw new CRM_Core_Exception("Unimplemented method: CRM_Core_Permission_*::uninstallPermissions"); } /** @@ -169,6 +181,7 @@ class CRM_Core_Permission_Base { * @see CRM_Core_Permission::getCorePermissions */ function upgradePermissions($module, $modulePermissions) { + throw new CRM_Core_Exception("Unimplemented method: CRM_Core_Permission_*::upgradePermissions"); } /** diff --git a/CRM/Core/Permission/Drupal.php b/CRM/Core/Permission/Drupal.php index f2b9a0c657..19750a8e1c 100644 --- a/CRM/Core/Permission/Drupal.php +++ b/CRM/Core/Permission/Drupal.php @@ -84,6 +84,13 @@ class CRM_Core_Permission_Drupal extends CRM_Core_Permission_DrupalBase{ return FALSE; } + /** + * {@inheritDoc} + */ + public function isModulePermissionSupported() { + return TRUE; + } + /** * Remove all vestiges of permissions for the given module. */ diff --git a/CRM/Extension/Manager/Module.php b/CRM/Extension/Manager/Module.php index 26ad3ca96c..7c2ce4768b 100644 --- a/CRM/Extension/Manager/Module.php +++ b/CRM/Extension/Manager/Module.php @@ -69,7 +69,9 @@ class CRM_Extension_Manager_Module extends CRM_Extension_Manager_Base { public function onPostUninstall(CRM_Extension_Info $info) { // Remove references to the module's permissions. $config = CRM_Core_Config::singleton(); - return $config->userPermissionClass->uninstallPermissions($info->file); + if ($config->userPermissionClass->isModulePermissionSupported()) { + $config->userPermissionClass->uninstallPermissions($info->file); + } // else: don't care because no permissions were installed! } public function onPreDisable(CRM_Extension_Info $info) { -- 2.25.1