1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 09:04:03 +00:00

Refactor condition logic for better readability

This commit is contained in:
Sean Taylor 2020-02-21 10:59:18 +00:00
parent 17b97d8324
commit e3fe37a849
No known key found for this signature in database
GPG key ID: 95C0F6D48AEA3D32

View file

@ -110,12 +110,20 @@ class TenancyServiceProvider extends ServiceProvider
// Queue tenancy
$this->app['events']->listen(\Illuminate\Queue\Events\JobProcessing::class, function ($event) {
$tenantId = $event->job->payload()['tenant_id'] ?? null;
if (
$tenantId !== null &&
(! tenancy()->initialized || tenancy('id') !== $tenantId)
) {
tenancy()->initById($tenantId);
// The job is not tenant-aware
if (! $tenantId) {
return;
}
// 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);
});
}
}