1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 19:54:03 +00:00

[4.x] Fix tenants:run argument parsing (#1287)

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

* Test that tenants:run parses the arguments correctly

* Fix code style (php-cs-fixer)

* Fix PHPStan issue

* remove unnecessary ()

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
This commit is contained in:
lukinovec 2025-01-11 12:03:09 +01:00 committed by GitHub
parent f955b38e2b
commit 0e223e0484
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 54 additions and 18 deletions

View file

@ -7,7 +7,7 @@ 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\Input\StringInput;
use Symfony\Component\Console\Output\ConsoleOutput;
class Run extends Command
@ -21,30 +21,19 @@ class Run extends Command
public function handle(): int
{
$argvInput = $this->argvInput();
/** @var string $commandName */
$commandName = $this->argument('commandname');
tenancy()->runForMultiple($this->getTenants(), function ($tenant) use ($argvInput) {
$stringInput = new StringInput($commandName);
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);
}
}