From 4463eb8939dbffdae096b2e3cddc279d1970a056 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Fri, 8 Apr 2022 15:43:18 +0900 Subject: [PATCH] Prevent negative transaction level by unnecessary rollback or commit --- common/framework/db.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/common/framework/db.php b/common/framework/db.php index c2ad7040e..35709b341 100644 --- a/common/framework/db.php +++ b/common/framework/db.php @@ -614,7 +614,11 @@ class DB { $this->_handle->exec(sprintf('ROLLBACK TO SAVEPOINT `%s%s%d`', $this->_prefix, 'savepoint', $this->_transaction_level - 1)); } - $this->_transaction_level--; + + if ($this->_transaction_level > 0) + { + $this->_transaction_level--; + } return $this->_transaction_level; } @@ -649,7 +653,21 @@ class DB Debug::addQuery($this->getQueryLog('NESTED COMMIT IGNORED BY RHYMIX', 0)); } } - $this->_transaction_level--; + + if ($this->_transaction_level > 0) + { + $this->_transaction_level--; + } + return $this->_transaction_level; + } + + /** + * Get the current transaction level. + * + * @return int + */ + public function getTransactionLevel(): int + { return $this->_transaction_level; }