DatabaseTransactionsManager
class DatabaseTransactionsManager
Manages database transaction callbacks in a coroutine-safe manner.
Uses Context to store transaction state per-coroutine, ensuring that concurrent requests don't interfere with each other's transactions.
Methods
Get all committed transactions for the current coroutine.
Get all pending transactions for the current coroutine.
Get current transaction for a connection.
Start a new database transaction.
Commit the root database transaction and execute callbacks.
Move relevant pending transactions to a committed state.
Rollback the active database transaction.
Remove all pending, completed, and current transactions for the given connection name.
Remove and return all committed descendants of the given transaction.
Execute commit callbacks for every detached transaction.
Execute rollback callbacks for every detached transaction.
Register a transaction callback.
Register a callback for transaction rollback.
Determine whether a callback would wait for an open transaction.
Get the latest applicable transaction, optionally limited to a connection.
Get the transactions that are applicable to callbacks.
Determine if after commit callbacks should be executed for the given transaction level.
Get all of the pending transactions.
Get all of the committed transactions.
Check whether there are pending transactions in non-coroutine storage.
Copy transaction state from the current coroutine to non-coroutine storage.
Restore the test lifecycle's transaction state in the current coroutine.
Clear all transaction state from non-coroutine storage.
Details
at line 26
protected Collection
getCommittedTransactionsInternal()
Get all committed transactions for the current coroutine.
at line 36
protected Collection
getPendingTransactionsInternal()
Get all pending transactions for the current coroutine.
at line 44
protected DatabaseTransactionRecord|null
getCurrentTransactionForConnection(string $connection)
Get current transaction for a connection.
at line 52
void
begin(string $connection, int $level)
Start a new database transaction.
at line 71
Collection
commit(string $connection, int $levelBeingCommitted, int $newTransactionLevel)
Commit the root database transaction and execute callbacks.
at line 107
void
stageTransactions(string $connection, int $levelBeingCommitted)
Move relevant pending transactions to a committed state.
at line 127
void
rollback(string $connection, int $newTransactionLevel)
Rollback the active database transaction.
at line 174
protected void
removeAllTransactionsForConnection(string $connection)
Remove all pending, completed, and current transactions for the given connection name.
at line 211
protected Collection
removeCommittedTransactionsThatAreChildrenOf(DatabaseTransactionRecord $transaction)
Remove and return all committed descendants of the given transaction.
at line 237
protected void
executeCommitCallbacks(Collection $transactions)
Execute commit callbacks for every detached transaction.
at line 263
protected void
executeRollbackCallbacks(Collection $transactions)
Execute rollback callbacks for every detached transaction.
at line 289
void
addCallback(callable $callback, string|null $connection = null)
Register a transaction callback.
A null connection selects the most recently started applicable transaction on any connection. The callback runs when that transaction and its enclosing stack on the same connection commit.
at line 308
void
addCallbackForRollback(callable $callback, string|null $connection = null)
Register a callback for transaction rollback.
A null connection selects the most recently started applicable transaction on any connection. The callback runs when that transaction and its enclosing stack on the same connection roll back.
at line 318
bool
hasApplicableTransaction(string|null $connection = null)
Determine whether a callback would wait for an open transaction.
at line 326
protected DatabaseTransactionRecord|null
latestApplicableTransaction(string|null $connection)
Get the latest applicable transaction, optionally limited to a connection.
at line 350
Collection
callbackApplicableTransactions()
Get the transactions that are applicable to callbacks.
at line 358
bool
afterCommitCallbacksShouldBeExecuted(int $level)
Determine if after commit callbacks should be executed for the given transaction level.
at line 368
Collection
getPendingTransactions()
Get all of the pending transactions.
at line 378
Collection
getCommittedTransactions()
Get all of the committed transactions.
at line 386
static bool
hasNonCoroutinePendingTransactions()
Check whether there are pending transactions in non-coroutine storage.
at line 400
static void
copyToNonCoroutineState()
Copy transaction state from the current coroutine to non-coroutine storage.
This copies coroutine-local transaction state into worker-global storage, so request-time use can leak or race across concurrent requests.
at line 415
static void
copyFromNonCoroutineState()
Restore the test lifecycle's transaction state in the current coroutine.
This deliberately shares transaction ownership across setup, test and teardown; normal child coroutines must own separate transactions.
at line 431
static void
clearNonCoroutineState()
Clear all transaction state from non-coroutine storage.
This mutates worker-global transaction state, so request-time use can race with concurrent requests using the same storage.