add method to check if we're inside a transaction

This commit is contained in:
Robin Appelman 2015-08-10 14:15:44 +02:00
parent 06065189d7
commit 58e96e53b0
3 changed files with 27 additions and 0 deletions

View File

@ -153,6 +153,15 @@ class Db implements IDb {
$this->connection->beginTransaction();
}
/**
* Check if a transaction is active
*
* @return bool
*/
public function inTransaction() {
return $this->connection->inTransaction();
}
/**
* Commit the database changes done during a transaction that is in progress
*/

View File

@ -291,4 +291,14 @@ class Connection extends \Doctrine\DBAL\Connection implements IDBConnection {
protected function replaceTablePrefix($statement) {
return str_replace( '*PREFIX*', $this->tablePrefix, $statement );
}
/**
* Check if a transaction is active
*
* @return bool
* @since 8.2.0
*/
public function inTransaction() {
return $this->getTransactionNestingLevel() > 0;
}
}

View File

@ -114,6 +114,14 @@ interface IDBConnection {
*/
public function beginTransaction();
/**
* Check if a transaction is active
*
* @return bool
* @since 8.2.0
*/
public function inTransaction();
/**
* Commit the database changes done during a transaction that is in progress
* @since 6.0.0