Esempio n. 1
1
 /**
  * @throws \yii\base\InvalidConfigException
  * @throws \yii\db\Exception
  */
 public function actionUpdate()
 {
     $assignments = $this->getAllAssignments();
     $useTransaction = $this->authManager instanceof \yii\rbac\DbManager && $this->useTransaction === true;
     $transaction = null;
     if ($useTransaction) {
         $transaction = $this->db->beginTransaction();
     }
     try {
         $this->authManager->removeAll();
         $this->updateRules();
         $this->updateRoles();
         $this->updatePermission();
         $this->updateInheritanceRoles();
         $this->updateInheritancePermissions();
         if (!empty($assignments)) {
             $this->restoreAssignments($assignments);
         }
         if ($transaction !== null) {
             $transaction->commit();
         }
     } catch (\Exception $e) {
         $this->stderr($e->getMessage() . PHP_EOL);
         if ($transaction !== null) {
             $transaction->rollBack();
         }
     }
     if ($this->authManager instanceof \yii\rbac\DbManager) {
         $this->authManager->invalidateCache();
     }
 }
Esempio n. 2
0
 /**
  * Updates RBAC configuration using current RBAC manager component.
  *
  * @param array $collection
  * @return bool
  * @throws InvalidConfigException
  */
 public function update(array $collection)
 {
     $this->_auth = Yii::$app->authManager;
     $this->generateItems($collection);
     $this->manageItems();
     $this->manageRelations();
     if ($this->_auth instanceof \yii\rbac\DbManager) {
         $this->_auth->invalidateCache();
     }
 }