mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 12:44:02 +00:00
Fix pullFromPendingPool() behavior (#70)
This commit is contained in:
parent
19631f4e9a
commit
85bdbd57f7
2 changed files with 7 additions and 11 deletions
|
|
@ -27,6 +27,7 @@ class JobBatchBootstrapper implements TenancyBootstrapper
|
|||
|
||||
public function bootstrap(Tenant $tenant): void
|
||||
{
|
||||
// todo@revisit
|
||||
// Update batch repository connection to use the tenant connection
|
||||
$this->previousConnection = $this->batchRepository->getConnection();
|
||||
$this->batchRepository->setConnection($this->databaseManager->connection('tenant'));
|
||||
|
|
|
|||
|
|
@ -73,20 +73,15 @@ trait HasPending
|
|||
}
|
||||
|
||||
/** Try to pull a tenant from the pool of pending tenants. */
|
||||
public static function pullPendingFromPool(bool $firstOrCreate = false, array $attributes = []): ?Tenant
|
||||
public static function pullPendingFromPool(bool $firstOrCreate = true, array $attributes = []): ?Tenant
|
||||
{
|
||||
if (! static::onlyPending()->exists()) {
|
||||
if (! $firstOrCreate) {
|
||||
return null;
|
||||
}
|
||||
|
||||
static::createPending($attributes);
|
||||
}
|
||||
|
||||
// A pending tenant is surely available at this point
|
||||
/** @var Model&Tenant $tenant */
|
||||
/** @var (Model&Tenant)|null $tenant */
|
||||
$tenant = static::onlyPending()->first();
|
||||
|
||||
if ($tenant === null) {
|
||||
return $firstOrCreate ? static::create($attributes) : null;
|
||||
}
|
||||
|
||||
event(new PullingPendingTenant($tenant));
|
||||
|
||||
$tenant->update(array_merge($attributes, [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue