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

Use StringInput instead of ArgvInput so that tenants:run accepts args properly

This commit is contained in:
lukinovec 2025-01-08 10:13:53 +01:00
parent f955b38e2b
commit 1750297225

View file

@ -7,8 +7,8 @@ namespace Stancl\Tenancy\Commands;
use Illuminate\Console\Command;
use Illuminate\Contracts\Console\Kernel;
use Stancl\Tenancy\Concerns\HasTenantOptions;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Input\StringInput;
class Run extends Command
{
@ -21,30 +21,16 @@ class Run extends Command
public function handle(): int
{
$argvInput = $this->argvInput();
$stringInput = (new StringInput($this->argument('commandname')));
tenancy()->runForMultiple($this->getTenants(), function ($tenant) use ($argvInput) {
tenancy()->runForMultiple($this->getTenants(), function ($tenant) use ($stringInput) {
$this->components->info("Tenant: {$tenant->getTenantKey()}");
$this->getLaravel()
->make(Kernel::class)
->handle($argvInput, new ConsoleOutput);
->handle($stringInput, new ConsoleOutput);
});
return 0;
}
protected function argvInput(): ArgvInput
{
/** @var string $commandName */
$commandName = $this->argument('commandname');
// Convert string command to array
$subCommand = explode(' ', $commandName);
// Add "artisan" as first parameter because ArgvInput expects "artisan" as first parameter and later removes it
array_unshift($subCommand, 'artisan');
return new ArgvInput($subCommand);
}
}