mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 06:24:04 +00:00
Reinitialize tenancy for queued jobs if tenant id has changed
This commit is contained in:
parent
bb46767257
commit
17b97d8324
1 changed files with 6 additions and 4 deletions
|
|
@ -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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue