1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-14 17:04:03 +00:00

get down to 21 phpstan errors

This commit is contained in:
Samuel Štancl 2022-09-29 23:39:35 +02:00
parent a94227a19c
commit f98a901aeb
16 changed files with 85 additions and 26 deletions

View file

@ -20,7 +20,7 @@ class Down extends DownCommand
protected $description = 'Put tenants into maintenance mode.';
public function handle(): void
public function handle(): int
{
// The base down command is heavily used. Instead of saving the data inside a file,
// the data is stored the tenant database, which means some Laravel features
@ -29,16 +29,18 @@ class Down extends DownCommand
$payload = $this->getDownDatabasePayload();
// This runs for all tenants if no --tenants are specified
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) use ($payload) {
tenancy()->runForMultiple($this->getTenants(), function ($tenant) use ($payload) {
$this->line("Tenant: {$tenant['id']}");
$tenant->putDownForMaintenance($payload);
});
$this->comment('Tenants are now in maintenance mode.');
return 0;
}
/** Get the payload to be placed in the "down" file. */
protected function getDownDatabasePayload()
protected function getDownDatabasePayload(): array
{
return [
'except' => $this->excludedPaths(),
@ -46,7 +48,7 @@ class Down extends DownCommand
'retry' => $this->getRetryTime(),
'refresh' => $this->option('refresh'),
'secret' => $this->option('secret'),
'status' => (int) $this->option('status', 503),
'status' => (int) ($this->option('status') ?? 503),
];
}
}

View file

@ -49,8 +49,8 @@ class Link extends Command
{
CreateStorageSymlinksAction::handle(
$tenants,
$this->option('relative') ?? false,
$this->option('force') ?? false,
(bool) ($this->option('relative') ?? false),
(bool) ($this->option('force') ?? false),
);
$this->info('The links have been created.');

View file

@ -36,7 +36,7 @@ class Rollback extends RollbackCommand
return 1;
}
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
tenancy()->runForMultiple($this->getTenants(), function ($tenant) {
$this->line("Tenant: {$tenant->getTenantKey()}");
event(new RollingBackDatabase($tenant));

View file

@ -6,11 +6,14 @@ 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.}
@ -19,7 +22,8 @@ class Run extends Command
public function handle(): void
{
$argvInput = $this->argvInput();
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) use ($argvInput) {
tenancy()->runForMultiple($this->getTenants(), function ($tenant) use ($argvInput) {
$this->line("Tenant: {$tenant->getTenantKey()}");
$this->getLaravel()
@ -30,12 +34,15 @@ class Run extends Command
protected function argvInput(): ArgvInput
{
/** @var string $commandname */
$commandname = $this->argument('commandname');
// Convert string command to array
$subCommand = explode(' ', $this->argument('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);
}
}

View file

@ -35,7 +35,7 @@ class Seed extends SeedCommand
return 1;
}
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
tenancy()->runForMultiple($this->getTenants(), function ($tenant) {
$this->line("Tenant: {$tenant->getTenantKey()}");
event(new SeedingDatabase($tenant));