diff --git a/src/Commands/Install.php b/src/Commands/Install.php index 830080a1..ab03fa55 100644 --- a/src/Commands/Install.php +++ b/src/Commands/Install.php @@ -12,7 +12,7 @@ class Install extends Command protected $description = 'Install stancl/tenancy.'; - public function handle(): void + public function handle(): int { $this->newLine(); @@ -72,6 +72,8 @@ class Install extends Command $this->patienceIsKeyToLife(); $this->askForSupport(); + + return 0; } /** diff --git a/src/Commands/Link.php b/src/Commands/Link.php index 9ca0ec73..0a587122 100644 --- a/src/Commands/Link.php +++ b/src/Commands/Link.php @@ -23,7 +23,7 @@ class Link extends Command protected $description = 'Create or remove tenant symbolic links.'; - public function handle(): void + public function handle(): int { $tenants = $this->getTenants(); @@ -35,7 +35,11 @@ class Link extends Command } } catch (Exception $exception) { $this->error($exception->getMessage()); + + return 1; } + + return 0; } protected function removeLinks(LazyCollection $tenants): void diff --git a/src/Commands/MigrateFresh.php b/src/Commands/MigrateFresh.php index 389883c3..23686b07 100644 --- a/src/Commands/MigrateFresh.php +++ b/src/Commands/MigrateFresh.php @@ -23,7 +23,7 @@ final class MigrateFresh extends Command $this->setName('tenants:migrate-fresh'); } - public function handle(): void + public function handle(): int { tenancy()->runForMultiple($this->getTenants(), function ($tenant) { $this->components->info("Tenant: {$tenant->getTenantKey()}"); @@ -44,5 +44,6 @@ final class MigrateFresh extends Command }); }); + return 0; } } diff --git a/src/Commands/Run.php b/src/Commands/Run.php index 3456026f..5ecc7c77 100644 --- a/src/Commands/Run.php +++ b/src/Commands/Run.php @@ -19,7 +19,7 @@ class Run extends Command protected $signature = 'tenants:run {commandname : The artisan command.} {--tenants=* : The tenant(s) to run the command for. Default: all}'; - public function handle(): void + public function handle(): int { $argvInput = $this->argvInput(); @@ -30,19 +30,21 @@ class Run extends Command ->make(Kernel::class) ->handle($argvInput, new ConsoleOutput); }); + + return 0; } protected function argvInput(): ArgvInput { - /** @var string $commandname */ - $commandname = $this->argument('commandname'); + /** @var string $commandName */ + $commandName = $this->argument('commandname'); // 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 - array_unshift($subcommand, 'artisan'); + array_unshift($subCommand, 'artisan'); - return new ArgvInput($subcommand); + return new ArgvInput($subCommand); } } diff --git a/src/Commands/TenantDump.php b/src/Commands/TenantDump.php index 9c8698c6..b42d2b68 100644 --- a/src/Commands/TenantDump.php +++ b/src/Commands/TenantDump.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Stancl\Tenancy\Commands; -use Illuminate\Console\Command; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Database\ConnectionResolverInterface; use Illuminate\Database\Console\DumpCommand; @@ -22,13 +21,6 @@ class TenantDump extends DumpCommand } 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() @@ -39,9 +31,15 @@ class TenantDump extends DumpCommand $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 diff --git a/src/Commands/TenantList.php b/src/Commands/TenantList.php index 61be5d37..15f362a8 100644 --- a/src/Commands/TenantList.php +++ b/src/Commands/TenantList.php @@ -14,7 +14,7 @@ class TenantList extends Command protected $description = 'List tenants.'; - public function handle(): void + public function handle(): int { $tenants = tenancy()->query()->cursor(); @@ -24,6 +24,8 @@ class TenantList extends Command /** @var Model&Tenant $tenant */ $this->components->twoColumnDetail($this->tenantCli($tenant), $this->domainsCli($tenant)); } + + return 0; } /** diff --git a/src/Commands/Up.php b/src/Commands/Up.php index 51e7eb0b..08c935c3 100644 --- a/src/Commands/Up.php +++ b/src/Commands/Up.php @@ -15,7 +15,7 @@ class Up extends Command protected $description = 'Put tenants out of maintenance mode.'; - public function handle(): void + public function handle(): int { tenancy()->runForMultiple($this->getTenants(), function ($tenant) { $this->components->info("Tenant: {$tenant->getTenantKey()}"); @@ -23,5 +23,7 @@ class Up extends Command }); $this->components->info('Tenants are now out of maintenance mode.'); + + return 0; } }