mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-06 00:54:03 +00:00
ensure tenant will rollback
This commit is contained in:
parent
126afcd0dd
commit
1634514069
1 changed files with 13 additions and 8 deletions
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Stancl\Tenancy;
|
namespace Stancl\Tenancy;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\Traits\Macroable;
|
use Illuminate\Support\Traits\Macroable;
|
||||||
|
|
@ -109,6 +110,8 @@ class Tenancy
|
||||||
*
|
*
|
||||||
* @param callable $callback
|
* @param callable $callback
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
*
|
||||||
|
* @throw Exception
|
||||||
*/
|
*/
|
||||||
public function central(callable $callback)
|
public function central(callable $callback)
|
||||||
{
|
{
|
||||||
|
|
@ -116,15 +119,17 @@ class Tenancy
|
||||||
|
|
||||||
$this->end();
|
$this->end();
|
||||||
|
|
||||||
// This callback will usually not accept arguments, but the previous
|
try {
|
||||||
// Tenant is the only value that can be useful here, so we pass that.
|
// This callback will usually not accept arguments, but the previous
|
||||||
$result = $callback($previousTenant);
|
// Tenant is the only value that can be useful here, so we pass that.
|
||||||
|
return $callback($previousTenant);
|
||||||
if ($previousTenant) {
|
} catch (Exception $e) {
|
||||||
$this->initialize($previousTenant);
|
throw $e;
|
||||||
|
} finally {
|
||||||
|
if ($previousTenant) {
|
||||||
|
$this->initialize($previousTenant);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue