Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ziaratban committed Dec 28, 2024
1 parent 3666c77 commit f45de4e
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() . ')');
Expand All @@ -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();
Expand All @@ -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() . ')');
Expand All @@ -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();
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down

0 comments on commit f45de4e

Please sign in to comment.