src/Controller/GroupPermissionsController.php
public function update()
    {
        if (!$this->request->is('post')) {
            if ($this->request->is('ajax')) {
                throw new MethodNotAllowedException();
            } else {
                $this->Flash->error($this->invalidRequestMessage);
                $this->redirect(['action' => 'index']);
                return;
            }
        }

        if (empty($this->request->data) && !$this->request->is('ajax')) {
            $this->Flash->warning(__d('wasabi_core', 'There are no permissions to update yet.'));
            $this->redirect(['action' => 'index']);
            return;
        }

        // save the new language positions
        $permissions = $this->GroupPermissions->patchEntities(
            $this->GroupPermissions->find('all'),
            $this->request->data
        );

        /** @var Connection $connection */
        $connection = $this->GroupPermissions->connection();
        $connection->begin();
        foreach ($permissions as $permission) {
            if (!$this->GroupPermissions->save($permission)) {
                $connection->rollback();
                break;
            }
        }

        if ($connection->inTransaction()) {
            $connection->commit();
            Cache::clear(false, 'wasabi/core/group_permissions');
            if ($this->request->is('ajax')) {
                $status = 'success';
                $this->set(compact('status'));
                $this->set('_serialize', ['status']);
            } else {
                $this->Flash->success(__d('wasabi_core', 'All permissions have been saved.'));
                $this->redirect(['action' => 'index']);
                return;
            }
        } else {
            $this->Flash->error($this->dbErrorMessage);
        }
    }
public function update()
    {
        if (!$this->request->is('post')) {
            if ($this->request->is('ajax')) {
                throw new MethodNotAllowedException();
            } else {
                $this->Flash->error($this->invalidRequestMessage);
                $this->redirect(['action' => 'index']);
                return;
            }
        }

        if (empty($this->request->data) && !$this->request->is('ajax')) {
            $this->Flash->warning(__d('wasabi_core', 'There are no permissions to update yet.'));
            $this->redirect(['action' => 'index']);
            return;
        }

        // save the new language positions
        $permissions = $this->GroupPermissions->patchEntities(
            $this->GroupPermissions->find('all'),
            $this->request->data
        );

        /** @var Connection $connection */
        $connection = $this->GroupPermissions->connection();
        $connection->begin();
        foreach ($permissions as $permission) {
            if (!$this->GroupPermissions->save($permission)) {
                $connection->rollback();
                break;
            }
        }

        if ($connection->inTransaction()) {
            $connection->commit();
            Cache::clear(false, 'wasabi/core/group_permissions');
            if ($this->request->is('ajax')) {
                $status = 'success';
                $this->set(compact('status'));
                $this->set('_serialize', ['status']);
            } else {
                $this->Flash->success(__d('wasabi_core', 'All permissions have been saved.'));
                $this->redirect(['action' => 'index']);
                return;
            }
        } else {
            $this->Flash->error($this->dbErrorMessage);
        }
    }
public function update ( ) { if ( ! $ this -> request -> is ( 'post' ) ) { if ( $ this -> request -> is ( 'ajax' ) ) { throw new MethodNotAllowedException ( ) ; } else { $ this -> Flash -> error ( $ this -> invalidRequestMessage ) ; $ this -> redirect ( [ 'action' => 'index' ] ) ; return ; } } if ( empty ( $ this -> request -> data ) && ! $ this -> request -> is ( 'ajax' ) ) { $ this -> Flash -> warning ( __d ( 'wasabi_core' , 'There are no permissions to update yet.' ) ) ; $ this -> redirect ( [ 'action' => 'index' ] ) ; return ; } // save the new language positions $ permissions = $ this -> GroupPermissions -> patchEntities ( $ this -> GroupPermissions -> find ( 'all' ) , $ this -> request -> data ) ; /** @var Connection $connection */ $ connection = $ this -> GroupPermissions -> connection ( ) ; $ connection -> begin ( ) ; foreach ( $ permissions as $ permission ) { if ( ! $ this -> GroupPermissions -> save ( $ permission ) ) { $ connection -> rollback ( ) ; break ; } } if ( $ connection -> inTransaction ( ) ) { $ connection -> commit ( ) ; Cache :: clear ( false , 'wasabi/core/group_permissions' ) ; if ( $ this -> request -> is ( 'ajax' ) ) { $ status = 'success' ; $ this -> set ( compact ( 'status' ) ) ; $ this -> set ( '_serialize' , [ 'status' ] ) ; } else { $ this -> Flash -> success ( __d ( 'wasabi_core' , 'All permissions have been saved.' ) ) ; $ this -> redirect ( [ 'action' => 'index' ] ) ; return ; } } else { $ this -> Flash -> error ( $ this -> dbErrorMessage ) ; } }
Update action
POST | AJAX

@return void
Update action POST | AJAX