Exemple #1
0
 /**
  * @param  array $attributes
  * @param  array $whiteList
  *
  * @return boolean
  * @throws Exception
  */
 private function makeRoot($attributes, $whiteList)
 {
     $owner = $this->getOwner();
     $owner->{$this->rootAttribute} = 0;
     $owner->{$this->leftAttribute} = 1;
     $owner->{$this->rightAttribute} = 2;
     $owner->{$this->levelAttribute} = 1;
     if ($this->hasManyRoots) {
         $this->db->begin();
         $this->ignoreEvent = true;
         if ($owner->create($attributes, $whiteList) == false) {
             $this->db->rollback();
             $this->ignoreEvent = false;
             return false;
         }
         $pk = $owner->{$this->rootAttribute} = $owner->{$this->primaryKey};
         $owner::findFirst($pk)->update([$this->rootAttribute => $pk]);
         $this->ignoreEvent = false;
         $this->db->commit();
     } else {
         if (count($owner->roots())) {
             throw new Exception('Cannot create more than one root in single root mode.');
         }
         if ($owner->create($attributes, $whiteList) == false) {
             return false;
         }
     }
     return true;
 }
Exemple #2
0
 /**
  * Rollbacks the transaction
  *
  * @param string|null $rollbackMessage
  * @param \Phalcon\Mvc\ModelInterface|null $rollbackRecord
  * @return boolean
  * @throws Exception
  */
 public function rollback($rollbackMessage = null, $rollbackRecord = null)
 {
     if (is_string($rollbackMessage) === false && is_null($rollbackMessage) === false) {
         throw new Exception('Invalid parameter type.');
     }
     if ((is_object($rollbackRecord) === false || $rollbackRecord instanceof ModelInterface === false) && is_null($rollbackRecord) === false) {
         throw new Exception('Invalid parameter type.');
     }
     if (is_object($this->_manager) === true) {
         call_user_func(array($this->_manager, 'notifyRollback'), $this);
     }
     if ($this->_connection->rollback() === true) {
         if (is_null($rollbackMessage) === true) {
             $rollbackMessage = 'Transaction aborted';
         }
         if (is_object($rollbackRecord) === true) {
             $this->_rollbackRecord = $rollbackRecord;
         }
         throw new Failed($rollbackMessage, $rollbackRecord);
     }
 }
Exemple #3
0
 /**
  * Rollback transaction
  * (happens automatically if commit never reached)
  *
  * @return $this
  */
 public function rollback()
 {
     $this->db->rollback();
     return $this;
 }