mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 21:14:03 +00:00
* Using laravel components * Ensure commands returns success * update tests * clean * bump EndBug version * Update ci.yml * Update ci.yml * Update ci.yml * revert CI changes * Update ci.yml * Update ci.yml * Update ci.yml * revert CI changes to it's original state * fix typos, improve code * improve Install & TenantList commands * php-cs-fixer * type GitHub properly Co-authored-by: Abrar Ahmad <abrar.dev99@gmail.com> Co-authored-by: Samuel Štancl <samuel@archte.ch> Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Stancl\Tenancy\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Contracts\Console\Kernel;
|
|
use Stancl\Tenancy\Concerns\HasATenantsOption;
|
|
use Symfony\Component\Console\Input\ArgvInput;
|
|
use Symfony\Component\Console\Output\ConsoleOutput;
|
|
|
|
class Run extends Command
|
|
{
|
|
use HasATenantsOption;
|
|
|
|
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
|
|
{
|
|
$argvInput = $this->argvInput();
|
|
|
|
tenancy()->runForMultiple($this->getTenants(), function ($tenant) use ($argvInput) {
|
|
$this->components->info("Tenant: {$tenant->getTenantKey()}");
|
|
|
|
$this->getLaravel()
|
|
->make(Kernel::class)
|
|
->handle($argvInput, 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);
|
|
}
|
|
}
|