package and depencies

This commit is contained in:
RafficMohammed
2023-01-08 02:57:24 +05:30
parent d5332eb421
commit 1d54b8bc7f
4309 changed files with 193331 additions and 172289 deletions

View File

@@ -11,6 +11,13 @@ class DatabaseTransactionsManager
*/
protected $transactions;
/**
* The database transaction that should be ignored by callbacks.
*
* @var \Illuminate\Database\DatabaseTransactionRecord
*/
protected $callbacksShouldIgnore;
/**
* Create a new database transactions manager instance.
*
@@ -44,10 +51,13 @@ class DatabaseTransactionsManager
*/
public function rollback($connection, $level)
{
$this->transactions = $this->transactions->reject(function ($transaction) use ($connection, $level) {
return $transaction->connection == $connection &&
$transaction->level > $level;
})->values();
$this->transactions = $this->transactions->reject(
fn ($transaction) => $transaction->connection == $connection && $transaction->level > $level
)->values();
if ($this->transactions->isEmpty()) {
$this->callbacksShouldIgnore = null;
}
}
/**
@@ -59,14 +69,16 @@ class DatabaseTransactionsManager
public function commit($connection)
{
[$forThisConnection, $forOtherConnections] = $this->transactions->partition(
function ($transaction) use ($connection) {
return $transaction->connection == $connection;
}
fn ($transaction) => $transaction->connection == $connection
);
$this->transactions = $forOtherConnections->values();
$forThisConnection->map->executeCallbacks();
if ($this->transactions->isEmpty()) {
$this->callbacksShouldIgnore = null;
}
}
/**
@@ -77,11 +89,36 @@ class DatabaseTransactionsManager
*/
public function addCallback($callback)
{
if ($current = $this->transactions->last()) {
if ($current = $this->callbackApplicableTransactions()->last()) {
return $current->addCallback($callback);
}
call_user_func($callback);
$callback();
}
/**
* Specify that callbacks should ignore the given transaction when determining if they should be executed.
*
* @param \Illuminate\Database\DatabaseTransactionRecord $transaction
* @return $this
*/
public function callbacksShouldIgnore(DatabaseTransactionRecord $transaction)
{
$this->callbacksShouldIgnore = $transaction;
return $this;
}
/**
* Get the transactions that are applicable to callbacks.
*
* @return \Illuminate\Support\Collection
*/
public function callbackApplicableTransactions()
{
return $this->transactions->reject(function ($transaction) {
return $transaction === $this->callbacksShouldIgnore;
})->values();
}
/**