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

Correct the tenant order in Run command

This commit is contained in:
lukinovec 2022-09-29 10:03:45 +02:00
parent cd37528399
commit 0ee54da29c

View file

@ -6,6 +6,7 @@ namespace Stancl\Tenancy\Commands;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Contracts\Console\Kernel; use Illuminate\Contracts\Console\Kernel;
use Stancl\Tenancy\Database\Models\Tenant;
use Stancl\Tenancy\Concerns\HasTenantOptions; use Stancl\Tenancy\Concerns\HasTenantOptions;
use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Console\Output\ConsoleOutput;
@ -34,7 +35,17 @@ class Run extends Command
public function handle() public function handle()
{ {
$argvInput = $this->ArgvInput(); $argvInput = $this->ArgvInput();
tenancy()->runForMultiple($this->getTenants(), function ($tenant) use ($argvInput) { $tenants = $this->getTenants();
if ($this->option('tenants')) {
// $this->getTenants() doesn't return tenants in the same order as the tenants passed in the tenants option
// Map the passed tenant keys to the fetched tenant models to correct the order
$tenants = array_map(function (string $tenantKey) use ($tenants) {
return $tenants->filter(fn(Tenant $tenant) => $tenant->getTenantKey() === $tenantKey)->first();
}, $this->option('tenants'));
}
tenancy()->runForMultiple($tenants, function ($tenant) use ($argvInput) {
$this->line("Tenant: {$tenant->getTenantKey()}"); $this->line("Tenant: {$tenant->getTenantKey()}");
$this->getLaravel() $this->getLaravel()