From 58e96e53b039365751eb8c4a2d511fcfcf507891 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 10 Aug 2015 14:15:44 +0200 Subject: [PATCH] add method to check if we're inside a transaction --- lib/private/appframework/db/db.php | 9 +++++++++ lib/private/db/connection.php | 10 ++++++++++ lib/public/idbconnection.php | 8 ++++++++ 3 files changed, 27 insertions(+) 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