mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-16 12:24:03 +00:00
* 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>
39 lines
1.1 KiB
PHP
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;
|
|
}
|
|
}
|