DboSource::commit PHP Method

commit() public method

Commit a transaction
public commit ( ) : boolean
return boolean True on success, false on fail (i.e. if the database/model does not support transactions, or a transaction has not started).
    public function commit()
    {
        if (!$this->_transactionStarted) {
            return false;
        }
        if ($this->_transactionNesting === 0) {
            if ($this->fullDebug) {
                $this->logQuery('COMMIT');
            }
            $this->_transactionStarted = false;
            return $this->_connection->commit();
        }
        if ($this->nestedTransactionSupported()) {
            return $this->_commitNested();
        }
        $this->_transactionNesting--;
        return true;
    }

Usage Example

 /**
  * Run migration
  *
  * @param string $direction, up or down direction of migration process
  * @return boolean Status of the process
  * @throws MigrationException
  */
 public function run($direction)
 {
     if (!in_array($direction, array('up', 'down'))) {
         throw new MigrationException($this, sprintf(__d('migrations', 'Migration direction (%s) is not one of valid directions.'), $direction), E_USER_NOTICE);
     }
     $this->direction = $direction;
     $null = null;
     $this->db = ConnectionManager::getDataSource($this->connection);
     $this->db->cacheSources = false;
     $this->db->begin($null);
     $this->Schema = new CakeSchema(array('connection' => $this->connection));
     try {
         $this->_invokeCallbacks('beforeMigration', $direction);
         $result = $this->_run();
         $this->_clearCache();
         $this->_invokeCallbacks('afterMigration', $direction);
         if (!$result) {
             return false;
         }
     } catch (Exception $e) {
         $this->db->rollback($null);
         throw $e;
     }
     return $this->db->commit($null);
 }
All Usage Examples Of DboSource::commit
DboSource