/**
  * Analyzes each plugin and adds any missing ACO path to the tree. It won't
  * remove any invalid ACO unless 'sync' GET parameter is present in URL.
  *
  * @return void Redirects to previous page
  */
 public function update()
 {
     $sync = !empty($this->request->query['sync']) ? true : false;
     if (AcoManager::buildAcos(null, $sync)) {
         $this->Flash->success(__d('user', 'Permissions tree was successfully updated!'));
     } else {
         $this->Flash->danger(__d('user', 'Some errors occur while updating permissions tree.'));
     }
     $this->title(__d('user', 'Update Permissions'));
     $this->redirect($this->referer());
 }
 /**
  * After installation is completed.
  *
  * @return void
  */
 protected function _finish()
 {
     global $classLoader;
     // composer's class loader instance
     snapshot();
     Plugin::dropCache();
     // trick: makes plugin visible to AcoManager
     $classLoader->addPsr4($this->_plugin['name'] . "\\", normalizePath(ROOT . "/plugins/{$this->_plugin['name']}/src"), true);
     AcoManager::buildAcos($this->_plugin['name']);
     $this->_reset();
 }
 /**
  * Removes all ACOs created by the plugin being uninstall.
  *
  * @return void
  */
 protected function _clearAcoPaths()
 {
     $this->loadModel('User.Acos');
     $nodes = $this->Acos->find()->where(['plugin' => $this->params['plugin']])->order(['lft' => 'ASC'])->all();
     foreach ($nodes as $node) {
         $this->Acos->removeFromTree($node);
         $this->Acos->delete($node);
     }
     AcoManager::buildAcos(null, true);
     // clear anything else
 }
Example #4
0
 /**
  * Gets a list of existing ACO paths for the given plugin, or the entire list
  * if no plugin is given.
  *
  * @param string $for Optional plugin name. e.g. `Taxonomy`
  * @return array All registered ACO paths
  */
 public static function paths($for = null)
 {
     if ($for !== null) {
         try {
             $for = plugin($for)->name;
         } catch (\Exception $e) {
             return [];
         }
     }
     $cacheKey = "paths({$for})";
     $paths = static::cache($cacheKey);
     if ($paths === null) {
         $paths = [];
         $aco = new AcoManager('__dummy__');
         $aco->loadModel('User.Acos');
         $leafs = $aco->Acos->find('all')->select(['id'])->where(['Acos.id NOT IN' => $aco->Acos->find()->select(['parent_id'])->where(['parent_id IS NOT' => null])]);
         foreach ($leafs as $leaf) {
             $path = $aco->Acos->find('path', ['for' => $leaf->id])->extract('alias')->toArray();
             $path = implode('/', $path);
             if ($for === null || $for !== null && str_starts_with($path, "{$for}/")) {
                 $paths[] = $path;
             }
         }
         static::cache($cacheKey, $paths);
     }
     return $paths;
 }