From f45de4eed7b3c57ec7d55faef7041b70b30bbfb6 Mon Sep 17 00:00:00 2001 From: Ziaratban Date: Sat, 28 Dec 2024 14:37:13 +0330 Subject: [PATCH] dev --- src/Transaction.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Transaction.php b/src/Transaction.php index dd9eb07b2..6fd7922d3 100644 --- a/src/Transaction.php +++ b/src/Transaction.php @@ -133,6 +133,8 @@ public function start($transactionOptions = []) */ public function commit() { + $this->queue = []; + $this->yiiDebug('Committing mongodb transaction ...', __METHOD__); $this->clientSession->mongoSession->commitTransaction(); $this->yiiEndProfile('mongodb > start transaction(session id => ' . $this->clientSession->getId() . ')'); @@ -147,6 +149,8 @@ public function commit() */ public function safeCommit(&$exception = null) { + $this->queue = []; + $this->yiiDebug('Committing mongodb transaction in safe mode ...', __METHOD__); try { $this->clientSession->mongoSession->commitTransaction(); @@ -167,6 +171,8 @@ public function safeCommit(&$exception = null) */ public function rollBack() { + $this->queue = []; + $this->yiiDebug('Rolling back mongodb transaction ...', __METHOD__); $this->clientSession->mongoSession->abortTransaction(); $this->yiiEndProfile('mongodb > start transaction(session id => ' . $this->clientSession->getId() . ')'); @@ -181,6 +187,8 @@ public function rollBack() */ public function safeRollBack(&$exception = null) { + $this->queue = []; + $this->yiiDebug('Rolling back mongodb transaction ...', __METHOD__); try { $this->clientSession->mongoSession->abortTransaction(); @@ -197,7 +205,7 @@ public function safeRollBack(&$exception = null) public function run($query, $throw = true, $log = false, $commit = false, $queue = false){ - if($queue){ + if($queue === true){ $this->queue[] = $query; return; } @@ -209,10 +217,13 @@ public function run($query, $throw = true, $log = false, $commit = false, $queue $this->clientSession->db->setSession($this->clientSession); if($output = $query()) { - foreach($this->queue as $_query){ - $_query(); + if($queue === 'run') + { + foreach($this->queue as $_query){ + $_query(); + } + $this->queue = []; } - $this->queue = []; if($commit){ return $this->safeCommit() ? $output : false;