mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 12:24:04 +00:00
Refactor condition logic for better readability
This commit is contained in:
parent
17b97d8324
commit
e3fe37a849
1 changed files with 13 additions and 5 deletions
|
|
@ -110,12 +110,20 @@ class TenancyServiceProvider extends ServiceProvider
|
||||||
// Queue tenancy
|
// Queue tenancy
|
||||||
$this->app['events']->listen(\Illuminate\Queue\Events\JobProcessing::class, function ($event) {
|
$this->app['events']->listen(\Illuminate\Queue\Events\JobProcessing::class, function ($event) {
|
||||||
$tenantId = $event->job->payload()['tenant_id'] ?? null;
|
$tenantId = $event->job->payload()['tenant_id'] ?? null;
|
||||||
if (
|
|
||||||
$tenantId !== null &&
|
// The job is not tenant-aware
|
||||||
(! tenancy()->initialized || tenancy('id') !== $tenantId)
|
if (! $tenantId) {
|
||||||
) {
|
return;
|
||||||
tenancy()->initById($tenantId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tenancy is already initialized for the tenant (e.g. dispatchNow was used)
|
||||||
|
if (tenancy()->initialized && tenant('id') === $tenantId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tenancy was either not initialized, or initialized for a different tenant.
|
||||||
|
// Therefore, we initialize it for the correct tenant.
|
||||||
|
tenancy()->initById($tenantId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue