diff --git a/lib/private/appframework/db/db.php b/lib/private/appframework/db/db.php index cde8583168..8e3fa6e419 100644 --- a/lib/private/appframework/db/db.php +++ b/lib/private/appframework/db/db.php @@ -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 */ diff --git a/lib/private/db/connection.php b/lib/private/db/connection.php index def3f2fd12..4d33cd968a 100644 --- a/lib/private/db/connection.php +++ b/lib/private/db/connection.php @@ -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; + } } diff --git a/lib/public/idbconnection.php b/lib/public/idbconnection.php index 0d04c43d73..6a4373583f 100644 --- a/lib/public/idbconnection.php +++ b/lib/public/idbconnection.php @@ -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