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

Reinitialize tenancy for queued jobs if tenant id has changed

This commit is contained in:
Sean Taylor 2020-01-23 17:29:57 +00:00
parent bb46767257
commit 17b97d8324
No known key found for this signature in database
GPG key ID: 95C0F6D48AEA3D32

View file

@ -109,10 +109,12 @@ 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) {
if (array_key_exists('tenant_id', $event->job->payload())) { $tenantId = $event->job->payload()['tenant_id'] ?? null;
if (! tenancy()->initialized) { // dispatchNow if (
tenancy()->initialize(tenancy()->find($event->job->payload()['tenant_id'])); $tenantId !== null &&
} (! tenancy()->initialized || tenancy('id') !== $tenantId)
) {
tenancy()->initById($tenantId);
} }
}); });
} }