mirror of
https://github.com/archtechx/tenancy.git
synced 2026-06-21 02:44:03 +00:00
Adds a --skip-tenants option to all tenant artisan commands (`tenants:run`, `tenants:migrate`, `tenants:rollback`, `tenants:seed`, `tenants:up`, `tenants:down`). The option is the complement of the existing `--tenants` option instead of specifying which tenants to include, you specify which to exclude. --------- Co-authored-by: Jimish Gamit <unique.jimish@gmail.com> Co-authored-by: Samuel Stancl <samuel@archte.ch> Co-authored-by: lukinovec <lukinovec@gmail.com>
40 lines
1.2 KiB
PHP
40 lines
1.2 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}
|
|
{--skip-tenants=* : The tenant(s) to skip}';
|
|
|
|
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;
|
|
}
|
|
}
|