1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 11:14:04 +00:00

Fix pullFromPendingPool() behavior (#70)

This commit is contained in:
Samuel Štancl 2024-11-25 04:44:39 +01:00 committed by GitHub
parent 19631f4e9a
commit 85bdbd57f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 11 deletions

View file

@ -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'));

View file

@ -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, [