/** * Create a permission deleting form. * * @param Horde_Perms_Permission $permission A permissions object. */ public function setupDeleteForm($permission) { /* Initialise form if required. */ $this->_formInit(); $this->_form->setTitle(sprintf(Horde_Core_Translation::t("Delete permissions for \"%s\""), $this->_corePerms->getTitle($permission->getName()))); $this->_form->setButtons(array(array('class' => 'horde-delete', 'value' => Horde_Core_Translation::t("Delete")), array('class' => 'horde-cancel', 'value' => Horde_Core_Translation::t("Do not delete")))); $this->_form->addHidden('', 'perm_id', 'text', false); $this->_form->addVariable(sprintf(Horde_Core_Translation::t("Delete permissions for \"%s\" and any sub-permissions?"), $this->_corePerms->getTitle($permission->getName())), 'prompt', 'description', false); }
/** * Removes a permission from the permissions system permanently. * * @param Horde_Perms_Permission_Sql $perm The permission to * remove. * @param boolean $force Force to remove every * child. * * @return boolean True if permission was deleted. * @throws Horde_Perms_Exception */ public function removePermission(Horde_Perms_Permission $perm, $force = false) { $name = $perm->getName(); $this->_cache->expire('perm_sql_' . $this->_cacheVersion . $name); $this->_cache->expire('perm_sql_exists_' . $this->_cacheVersion . $name); $query = 'DELETE FROM ' . $this->_params['table'] . ' WHERE perm_name = ?'; try { $result = $this->_db->delete($query, array($name)); } catch (Horde_Db_Exception $e) { throw new Horde_Perms_Exception($e); } if (!$force) { return (bool) $result; } /* Need to expire cache for all sub-permissions. */ try { $sub = $this->_db->selectValues('SELECT perm_name FROM ' . $this->_params['table'] . ' WHERE perm_name LIKE ?', array($name . ':%')); foreach ($sub as $val) { $this->_cache->expire('perm_sql_' . $this->_cacheVersion . $val); $this->_cache->expire('perm_sql_exists_' . $this->_cacheVersion . $val); } } catch (Horde_Db_Exception $e) { } $query = 'DELETE FROM ' . $this->_params['table'] . ' WHERE perm_name LIKE ?'; try { return (bool) $this->_db->delete($query, array($name . ':%')); } catch (Horde_Db_Exception $e) { throw new Horde_Perms_Exception($e); } }