mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 18:34:04 +00:00
Ensure commands returns success
This commit is contained in:
parent
2f15dd5473
commit
27eb4f738e
7 changed files with 32 additions and 21 deletions
|
|
@ -12,7 +12,7 @@ class Install extends Command
|
||||||
|
|
||||||
protected $description = 'Install stancl/tenancy.';
|
protected $description = 'Install stancl/tenancy.';
|
||||||
|
|
||||||
public function handle(): void
|
public function handle(): int
|
||||||
{
|
{
|
||||||
$this->newLine();
|
$this->newLine();
|
||||||
|
|
||||||
|
|
@ -72,6 +72,8 @@ class Install extends Command
|
||||||
|
|
||||||
$this->patienceIsKeyToLife();
|
$this->patienceIsKeyToLife();
|
||||||
$this->askForSupport();
|
$this->askForSupport();
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ class Link extends Command
|
||||||
|
|
||||||
protected $description = 'Create or remove tenant symbolic links.';
|
protected $description = 'Create or remove tenant symbolic links.';
|
||||||
|
|
||||||
public function handle(): void
|
public function handle(): int
|
||||||
{
|
{
|
||||||
$tenants = $this->getTenants();
|
$tenants = $this->getTenants();
|
||||||
|
|
||||||
|
|
@ -35,7 +35,11 @@ class Link extends Command
|
||||||
}
|
}
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
$this->error($exception->getMessage());
|
$this->error($exception->getMessage());
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function removeLinks(LazyCollection $tenants): void
|
protected function removeLinks(LazyCollection $tenants): void
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ final class MigrateFresh extends Command
|
||||||
$this->setName('tenants:migrate-fresh');
|
$this->setName('tenants:migrate-fresh');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handle(): void
|
public function handle(): int
|
||||||
{
|
{
|
||||||
tenancy()->runForMultiple($this->getTenants(), function ($tenant) {
|
tenancy()->runForMultiple($this->getTenants(), function ($tenant) {
|
||||||
$this->components->info("Tenant: {$tenant->getTenantKey()}");
|
$this->components->info("Tenant: {$tenant->getTenantKey()}");
|
||||||
|
|
@ -44,5 +44,6 @@ final class MigrateFresh extends Command
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ class Run extends Command
|
||||||
protected $signature = 'tenants:run {commandname : The artisan command.}
|
protected $signature = 'tenants:run {commandname : The artisan command.}
|
||||||
{--tenants=* : The tenant(s) to run the command for. Default: all}';
|
{--tenants=* : The tenant(s) to run the command for. Default: all}';
|
||||||
|
|
||||||
public function handle(): void
|
public function handle(): int
|
||||||
{
|
{
|
||||||
$argvInput = $this->argvInput();
|
$argvInput = $this->argvInput();
|
||||||
|
|
||||||
|
|
@ -30,19 +30,21 @@ class Run extends Command
|
||||||
->make(Kernel::class)
|
->make(Kernel::class)
|
||||||
->handle($argvInput, new ConsoleOutput);
|
->handle($argvInput, new ConsoleOutput);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function argvInput(): ArgvInput
|
protected function argvInput(): ArgvInput
|
||||||
{
|
{
|
||||||
/** @var string $commandname */
|
/** @var string $commandName */
|
||||||
$commandname = $this->argument('commandname');
|
$commandName = $this->argument('commandname');
|
||||||
|
|
||||||
// Convert string command to array
|
// Convert string command to array
|
||||||
$subcommand = explode(' ', $commandname);
|
$subCommand = explode(' ', $commandName);
|
||||||
|
|
||||||
// Add "artisan" as first parameter because ArgvInput expects "artisan" as first parameter and later removes it
|
// Add "artisan" as first parameter because ArgvInput expects "artisan" as first parameter and later removes it
|
||||||
array_unshift($subcommand, 'artisan');
|
array_unshift($subCommand, 'artisan');
|
||||||
|
|
||||||
return new ArgvInput($subcommand);
|
return new ArgvInput($subCommand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Stancl\Tenancy\Commands;
|
namespace Stancl\Tenancy\Commands;
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
use Illuminate\Database\ConnectionResolverInterface;
|
use Illuminate\Database\ConnectionResolverInterface;
|
||||||
use Illuminate\Database\Console\DumpCommand;
|
use Illuminate\Database\Console\DumpCommand;
|
||||||
|
|
@ -22,13 +21,6 @@ class TenantDump extends DumpCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handle(ConnectionResolverInterface $connections, Dispatcher $dispatcher): int
|
public function handle(ConnectionResolverInterface $connections, Dispatcher $dispatcher): int
|
||||||
{
|
|
||||||
$this->tenant()->run(fn () => parent::handle($connections, $dispatcher));
|
|
||||||
|
|
||||||
return Command::SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function tenant(): Tenant
|
|
||||||
{
|
{
|
||||||
$tenant = $this->option('tenant')
|
$tenant = $this->option('tenant')
|
||||||
?? tenant()
|
?? tenant()
|
||||||
|
|
@ -39,9 +31,15 @@ class TenantDump extends DumpCommand
|
||||||
$tenant = tenancy()->find($tenant);
|
$tenant = tenancy()->find($tenant);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw_if(! $tenant, 'Could not identify the tenant to use for dumping the schema.');
|
if (is_null($tenant)){
|
||||||
|
$this->components->error("Could not find tenant to use for dumping the schema.");
|
||||||
|
|
||||||
return $tenant;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
parent::handle($connections, $dispatcher);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getOptions(): array
|
protected function getOptions(): array
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ class TenantList extends Command
|
||||||
|
|
||||||
protected $description = 'List tenants.';
|
protected $description = 'List tenants.';
|
||||||
|
|
||||||
public function handle(): void
|
public function handle(): int
|
||||||
{
|
{
|
||||||
$tenants = tenancy()->query()->cursor();
|
$tenants = tenancy()->query()->cursor();
|
||||||
|
|
||||||
|
|
@ -24,6 +24,8 @@ class TenantList extends Command
|
||||||
/** @var Model&Tenant $tenant */
|
/** @var Model&Tenant $tenant */
|
||||||
$this->components->twoColumnDetail($this->tenantCli($tenant), $this->domainsCli($tenant));
|
$this->components->twoColumnDetail($this->tenantCli($tenant), $this->domainsCli($tenant));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ class Up extends Command
|
||||||
|
|
||||||
protected $description = 'Put tenants out of maintenance mode.';
|
protected $description = 'Put tenants out of maintenance mode.';
|
||||||
|
|
||||||
public function handle(): void
|
public function handle(): int
|
||||||
{
|
{
|
||||||
tenancy()->runForMultiple($this->getTenants(), function ($tenant) {
|
tenancy()->runForMultiple($this->getTenants(), function ($tenant) {
|
||||||
$this->components->info("Tenant: {$tenant->getTenantKey()}");
|
$this->components->info("Tenant: {$tenant->getTenantKey()}");
|
||||||
|
|
@ -23,5 +23,7 @@ class Up extends Command
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->components->info('Tenants are now out of maintenance mode.');
|
$this->components->info('Tenants are now out of maintenance mode.');
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue