/** * Singleton * @return Application_Model_AclResourcesMapper */ public static function i() { if (self::$_instance == null) { self::$_instance = new self(); } return self::$_instance; }
public function getResourceDescriptor($resourceKey) { // check cache first if (isset($this->resourcesCache[$resourceKey])) { return $this->resourcesCache[$resourceKey]; } $resourceDescriptor = new Application_Model_AclResource(); Application_Model_AclResourcesMapper::i()->find($resourceKey, $resourceDescriptor); $this->resourcesCache[$resourceKey] = $resourceDescriptor; return $resourceDescriptor; }
private function _uninstall($manifest) { /* @var $egg X_Egg */ $egg = X_Egg::factory($manifest, APPLICATION_PATH . '/../'); foreach ($egg->getFiles() as $file) { /* @var $file X_Egg_File */ // if file doesn't exists, ignore it // this prevent errors when you retry to uninstall // a partially installed plugin if (!file_exists($file->getDestination())) { continue; } if (!$file->getProperty(X_Egg_File::P_REPLACE, false) || $file->getProperty(X_Egg_File::P_REMOVEREPLACEDONUNINSTALL, false)) { $unlinkStatus = @unlink($file->getDestination()); if (!$file->getProperty(X_Egg_File::P_IGNOREUNLINKERROR, true) && !$unlinkStatus) { X_Debug::e("File not unlinked: {{$file->getDestination()}}"); throw new Exception("Cannot unlink file {{$file->getDestination()}} and ignoreUnlinkError flag is FALSE. Remove it manually and try again"); } } else { X_Debug::i("Replaced file {{$file->getDestination()}} left because removeReplacedOnUninstall is FALSE"); } } $uninstallSql = $egg->getUninstallSQL(); if ($uninstallSql !== null && file_exists(dirname($manifest) . "/uninstall.sql")) { try { $dataSql = file_get_contents(dirname($manifest) . "/uninstall.sql"); if (trim($dataSql) !== '') { $bootstrap = $this->getFrontController()->getParam('bootstrap'); $db = $bootstrap->getResource('db'); $db->getConnection()->exec($dataSql); } } catch (Exception $e) { X_Debug::e("DB Error while uninstalling: {$e->getMessage()}"); $this->_helper->flashMessenger(X_Env::_('plugin_err_uninstallerror_sqlerror') . ": {$e->getMessage()}"); } @unlink(dirname($manifest) . "/uninstall.sql"); } // process acl fragment $aclHelper = X_VlcShares_Plugins::helpers()->acl(); // added classes foreach ($egg->getAclClasses() as $aclClass) { /* @var $aclClass X_Egg_AclClass */ $resources = Application_Model_AclResourcesMapper::i()->fetchByClassNotGenerated($aclClass->getName(), $egg->getKey()); $restore = $aclClass->getOnDelete(); foreach ($resources as $resource) { /* @var $resource Application_Model_AclResource */ $resource->setClass($restore); try { Application_Model_AclResourcesMapper::i()->save($resource); } catch (Exception $e) { X_Debug::e("Can't restore class {{$restore}} for resource {{$resource->getKey()}}: {$e->getMessage()}"); } } $aclHelper->removeClass($aclClass->getName()); } // acl resources are automatically removed by foreign key with generator @unlink($manifest); @rmdir(dirname($manifest)); return true; }
function saveAction() { $type = $this->getRequest()->getParam('type', false); if (!$type || !$this->getRequest()->isPost()) { $this->_helper->flashMessenger(array('type' => 'error', 'text' => X_Env::_('p_auth_err_invalidrequest'))); $this->_helper->redirector('index', 'acl'); return; } if ($type == 'resource') { $form = new Application_Form_AclResource(); $_classes = X_VlcShares_Plugins::helpers()->acl()->getClasses(); $classes = array(); foreach ($_classes as $perm) { /* @var $perm Application_Model_AclClass */ $classes[$perm->getName()] = "{$perm->getName()}"; } $form->class->setMultiOptions($classes); $form->setDefault('class', Application_Model_AclClass::CLASS_BROWSE); $_plugins = X_VlcShares_Plugins::broker()->getPlugins(); $plugins = array(); foreach ($_plugins as $id => $plugin) { $plugins[$id] = $id == 'auth' ? 'CORE' : $id; } $form->generator->setMultiOptions($plugins); $form->setDefault('generator', 'auth'); } else { $type = 'class'; $form = new Application_Form_AclClass(); } if ($form->isValid($this->getRequest()->getPost())) { if ($type == 'resource') { $key = $form->getValue('key'); $key = "default/{$key}"; $model = new Application_Model_AclResource(); $mapper = Application_Model_AclResourcesMapper::i(); $mapper->find($key, $model); if ($model->isNew()) { $model->setKey($key); $model->setGenerator($form->getValue('generator')); $model->setClass($form->getValue('class')); X_Debug::i("Adding resource {key: {$model->getKey()}, class: {$model->getClass()}, generator: {$model->getGenerator()}}"); } else { throw new Exception("This resource key already exists {{$key}}"); } } elseif ($type == 'class') { $model = new Application_Model_AclClass(); $mapper = Application_Model_AclClassesMapper::i(); $mapper->find($form->getValue('name'), $model); if ($model->isNew()) { $model->setName($form->getValue('name')); $model->setDescription($form->getValue('description')); X_Debug::i("Adding class {name: {$model->getName()}}"); } else { throw new Exception("This class already exists {{$form->getValue('name')}}"); } } else { throw new Exception("Invalid type {{$type}}"); } try { $mapper->save($model); $this->_helper->flashMessenger(array('type' => 'success', 'text' => X_Env::_('p_auth_acl_datasaved'))); $this->_helper->redirector('index', 'acl'); } catch (Exception $e) { $this->_helper->flashMessenger(array('type' => 'error', 'text' => X_Env::_('p_auth_dberror', $e->getMessage()))); $this->_helper->redirector('index', 'acl'); } } else { $form->setAction($this->_helper->url('save', 'acl', 'default', array('type' => $type))); $form->setDefaults($this->getRequest()->getPost()); $this->view->type = $type; $this->view->form = $form; $this->_helper->viewRenderer->setScriptAction('add'); } }