Cake\Database\Connection::rollback PHP Method

rollback() public method

Rollback current transaction.
public rollback ( ) : boolean
return boolean
    public function rollback()
    {
        if (!$this->_transactionStarted) {
            return false;
        }
        $useSavePoint = $this->useSavePoints();
        if ($this->_transactionLevel === 0 || !$useSavePoint) {
            $this->_transactionLevel = 0;
            $this->_transactionStarted = false;
            if ($this->_logQueries) {
                $this->log('ROLLBACK');
            }
            $this->_driver->rollbackTransaction();
            return true;
        }
        if ($useSavePoint) {
            $this->rollbackSavepoint($this->_transactionLevel--);
        }
        return true;
    }

Usage Example

 /**
  * @param object $command
  * @param callable $next
  *
  * @return mixed
  * @throws \Exception when Transaction fails to commit.
  */
 public function execute($command, callable $next)
 {
     $this->connection->begin();
     try {
         $returnValue = $next($command);
         $isCommitted = $this->connection->commit();
     } catch (\Exception $e) {
         $this->connection->rollback();
         throw $e;
     }
     if (!$isCommitted) {
         throw new \Exception('Failed to commit the transaction.');
     }
     return $returnValue;
 }
All Usage Examples Of Cake\Database\Connection::rollback