Skip to content

Commit

Permalink
Possible solution for weird edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusjatenee committed Nov 23, 2023
1 parent bf3f912 commit c21ad42
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Illuminate/Database/DatabaseTransactionsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ class DatabaseTransactionsManager
*/
protected $currentlyBeingExecutedTransaction = null;


/**
* The ledger of recent transactions.
*
* @var \Illuminate\Database\DatabaseTransactionRecord[]
*/
protected $recentTransactions = [];

/**
* Start a new database transaction.
*
Expand All @@ -48,6 +56,7 @@ public function begin($connection, $level)
}

$this->movePointersTo($connection, $newTransaction);
$this->recentTransactions[] = $newTransaction;

return $newTransaction;
}
Expand Down Expand Up @@ -85,6 +94,13 @@ public function rollback($connection)

$this->getParentTransaction($connection)?->removeChild($this->currentlyBeingExecutedTransaction);
$this->movePointersTo($connection, $this->currentTransaction[$connection]->parent);

if (is_null($this->currentlyBeingExecutedTransaction)) {
$lastTransaction = (new Collection($this->recentTransactions))
->reject(fn ($transaction) => $transaction->connection === $connection)->last();

$this->movePointersTo($lastTransaction->connection, $lastTransaction);
}
}

/**
Expand Down

0 comments on commit c21ad42

Please sign in to comment.