Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
AnourValar committed May 24, 2020
1 parent c9cd1db commit 62bd16d
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function onCommit(callable $closure, string $connection = null) : void
$connection = \DB::getDefaultConnection();
}

if (! \DB::connection($connection)->transactionLevel()) {
if ($this->shouldCommit($connection)) {
$closure();
return;
}
Expand All @@ -99,7 +99,7 @@ public function onCommit(callable $closure, string $connection = null) : void
return;
}

if (! \DB::connection($connection)->transactionLevel()) {
if ($this->shouldCommit($connection)) {
$triggered = true;
if ($event instanceof TransactionCommitted) {
$closure();
Expand All @@ -121,7 +121,7 @@ public function onRollBack(callable $closure, string $connection = null) : void
$connection = \DB::getDefaultConnection();
}

if (! \DB::connection($connection)->transactionLevel()) {
if ($this->shouldRollBack($connection)) {
return;
}

Expand All @@ -133,7 +133,7 @@ public function onRollBack(callable $closure, string $connection = null) : void
return;
}

if (! \DB::connection($connection)->transactionLevel()) {
if ($this->shouldRollBack($connection)) {
$triggered = true;
if ($event instanceof TransactionRolledBack) {
$closure();
Expand Down Expand Up @@ -186,4 +186,22 @@ protected function cleanUp(\Illuminate\Database\Connection $connection, string $
->delete();
}
}

/**
* @param mixed $connection
* @return boolean
*/
protected function shouldCommit($connection)
{
return (! \DB::connection($connection)->transactionLevel());
}

/**
* @param mixed $connection
* @return boolean
*/
protected function shouldRollBack($connection)
{
return (! \DB::connection($connection)->transactionLevel());
}
}

0 comments on commit 62bd16d

Please sign in to comment.