/**
  * Tries to replace the owner by the new owner.
  * 
  * If the logged in user can not perform the operation a new RequestChangeOwnership object is created.
  * 
  * 
  * @throws \MapasCulturais\Exceptions\PermissionDenied
  * @throws \MapasCulturais\Exceptions\WorkflowRequestTransport
  * 
  * @workflow RequestChangeOwnership
  */
 protected function _saveOwnerAgent()
 {
     if (!$this->owner && $this->_newOwner || $this->_newOwner && !$this->_newOwner->equals($this->owner)) {
         try {
             $this->checkPermission('changeOwner');
             $this->_newOwner->checkPermission('modify');
             $this->owner = $this->_newOwner;
         } catch (\MapasCulturais\Exceptions\PermissionDenied $e) {
             $app = App::i();
             if (!$app->isWorkflowEnabled()) {
                 throw $e;
             }
             $ar = new \MapasCulturais\Entities\RequestChangeOwnership();
             $ar->origin = $this;
             $ar->destination = $this->_newOwner;
             throw new \MapasCulturais\Exceptions\WorkflowRequestTransport($ar);
         }
     }
 }
示例#2
0
 protected function _saveNested($flush = false)
 {
     if ($this->_newParent !== false) {
         $app = App::i();
         if (is_object($this->parent) && is_object($this->_newParent) && $this->parent->equals($this->_newParent) || is_null($this->parent) && is_null($this->_newParent)) {
             return;
         }
         try {
             $this->checkPermission('changeOwner');
             if ($this->_newParent) {
                 $this->_newParent->checkPermission('@control');
                 $this->parent = $this->_newParent;
                 $this->user = $this->_newUser;
                 $this->_newParent = false;
             }
         } catch (\MapasCulturais\Exceptions\PermissionDenied $e) {
             if (!$app->isWorkflowEnabled()) {
                 throw $e;
             }
             $destination = $this->_newParent;
             $this->_newParent = false;
             $ar = new \MapasCulturais\Entities\RequestChangeOwnership();
             $ar->origin = $this;
             $ar->destination = $destination;
             throw new \MapasCulturais\Exceptions\WorkflowRequestTransport($ar);
         }
     }
 }