1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-16 12:24:03 +00:00
tenancy/src/Commands/Run.php
lukinovec 0e223e0484
[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>
2025-01-11 12:03:09 +01:00

39 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Commands;
use Illuminate\Console\Command;
use Illuminate\Contracts\Console\Kernel;
use Stancl\Tenancy\Concerns\HasTenantOptions;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\ConsoleOutput;
class Run extends Command
{
use HasTenantOptions;
protected $description = 'Run a command for tenant(s)';
protected $signature = 'tenants:run {commandname : The artisan command.}
{--tenants=* : The tenant(s) to run the command for. Default: all}';
public function handle(): int
{
/** @var string $commandName */
$commandName = $this->argument('commandname');
$stringInput = new StringInput($commandName);
tenancy()->runForMultiple($this->getTenants(), function ($tenant) use ($stringInput) {
$this->components->info("Tenant: {$tenant->getTenantKey()}");
$this->getLaravel()
->make(Kernel::class)
->handle($stringInput, new ConsoleOutput);
});
return 0;
}
}