1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-06 07:44:04 +00:00

ensure tenant will rollback

This commit is contained in:
bepsvpt 2020-11-23 17:41:18 +08:00
parent 126afcd0dd
commit 1634514069
No known key found for this signature in database
GPG key ID: 6700B07822B5F1BF

View file

@ -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();
try {
// This callback will usually not accept arguments, but the previous // This callback will usually not accept arguments, but the previous
// Tenant is the only value that can be useful here, so we pass that. // Tenant is the only value that can be useful here, so we pass that.
$result = $callback($previousTenant); return $callback($previousTenant);
} catch (Exception $e) {
throw $e;
} finally {
if ($previousTenant) { if ($previousTenant) {
$this->initialize($previousTenant); $this->initialize($previousTenant);
} }
}
return $result;
} }
/** /**