*/
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'
+ );
+ }
}
}
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");
}
/**
* @see CRM_Core_Permission::getCorePermissions
*/
function upgradePermissions($module, $modulePermissions) {
+ throw new CRM_Core_Exception("Unimplemented method: CRM_Core_Permission_*::upgradePermissions");
}
/**
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) {