mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 04:34:03 +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
|
||||
$this->app['events']->listen(\Illuminate\Queue\Events\JobProcessing::class, function ($event) {
|
||||
if (array_key_exists('tenant_id', $event->job->payload())) {
|
||||
if (! tenancy()->initialized) { // dispatchNow
|
||||
tenancy()->initialize(tenancy()->find($event->job->payload()['tenant_id']));
|
||||
}
|
||||
$tenantId = $event->job->payload()['tenant_id'] ?? null;
|
||||
if (
|
||||
$tenantId !== null &&
|
||||
(! tenancy()->initialized || tenancy('id') !== $tenantId)
|
||||
) {
|
||||
tenancy()->initById($tenantId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue