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

phpstan, global_cache, resolver improvements, InitializationHelpers trait

This commit is contained in:
Samuel Štancl 2022-09-29 02:47:13 +02:00
parent fd65cf1754
commit 87212e5390
35 changed files with 170 additions and 231 deletions

View file

@ -8,24 +8,11 @@ use Illuminate\Console\Command;
class Install extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'tenancy:install';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Install stancl/tenancy.';
/**
* Execute the console command.
*/
public function handle()
public function handle(): void
{
$this->comment('Installing stancl/tenancy...');
$this->callSilent('vendor:publish', [

View file

@ -15,30 +15,15 @@ class Link extends Command
{
use HasATenantsOption;
/**
* The console command signature.
*
* @var string
*/
protected $signature = 'tenants:link
{--tenants=* : The tenant(s) to run the command for. Default: all}
{--relative : Create the symbolic link using relative paths}
{--force : Recreate existing symbolic links}
{--remove : Remove symbolic links}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create or remove tenant symbolic links.';
/**
* Execute the console command.
*
* @return void
*/
public function handle()
public function handle(): void
{
$tenants = $this->getTenants();

View file

@ -7,7 +7,6 @@ namespace Stancl\Tenancy\Commands;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Database\Console\Migrations\MigrateCommand;
use Illuminate\Database\Migrations\Migrator;
use Stancl\Tenancy\Concerns\DealsWithMigrations;
use Stancl\Tenancy\Concerns\ExtendsLaravelCommand;
use Stancl\Tenancy\Concerns\HasATenantsOption;
use Stancl\Tenancy\Events\DatabaseMigrated;
@ -15,7 +14,7 @@ use Stancl\Tenancy\Events\MigratingDatabase;
class Migrate extends MigrateCommand
{
use HasATenantsOption, DealsWithMigrations, ExtendsLaravelCommand;
use HasATenantsOption, ExtendsLaravelCommand;
protected $description = 'Run migrations for tenant(s)';
@ -31,10 +30,7 @@ class Migrate extends MigrateCommand
$this->specifyParameters();
}
/**
* Execute the console command.
*/
public function handle()
public function handle(): int
{
foreach (config('tenancy.migration_parameters') as $parameter => $value) {
if (! $this->input->hasParameterOption($parameter)) {
@ -43,10 +39,10 @@ class Migrate extends MigrateCommand
}
if (! $this->confirmToProceed()) {
return;
return 1;
}
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
tenancy()->runForMultiple($this->getTenants(), function ($tenant) {
$this->line("Tenant: {$tenant->getTenantKey()}");
event(new MigratingDatabase($tenant));
@ -56,5 +52,7 @@ class Migrate extends MigrateCommand
event(new DatabaseMigrated($tenant));
});
return 0;
}
}

View file

@ -5,19 +5,13 @@ declare(strict_types=1);
namespace Stancl\Tenancy\Commands;
use Illuminate\Console\Command;
use Stancl\Tenancy\Concerns\DealsWithMigrations;
use Stancl\Tenancy\Concerns\HasATenantsOption;
use Symfony\Component\Console\Input\InputOption;
final class MigrateFresh extends Command
{
use HasATenantsOption, DealsWithMigrations;
use HasATenantsOption;
/**
* The console command description.
*
* @var string
*/
protected $description = 'Drop all tables and re-run all migrations for tenant(s)';
public function __construct()
@ -29,12 +23,9 @@ final class MigrateFresh extends Command
$this->setName('tenants:migrate-fresh');
}
/**
* Execute the console command.
*/
public function handle()
public function handle(): void
{
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
tenancy()->runForMultiple($this->getTenants(), function ($tenant) {
$this->info('Dropping tables.');
$this->call('db:wipe', array_filter([
'--database' => 'tenant',

View file

@ -6,7 +6,6 @@ namespace Stancl\Tenancy\Commands;
use Illuminate\Database\Console\Migrations\RollbackCommand;
use Illuminate\Database\Migrations\Migrator;
use Stancl\Tenancy\Concerns\DealsWithMigrations;
use Stancl\Tenancy\Concerns\ExtendsLaravelCommand;
use Stancl\Tenancy\Concerns\HasATenantsOption;
use Stancl\Tenancy\Events\DatabaseRolledBack;
@ -14,25 +13,10 @@ use Stancl\Tenancy\Events\RollingBackDatabase;
class Rollback extends RollbackCommand
{
use HasATenantsOption, DealsWithMigrations, ExtendsLaravelCommand;
use HasATenantsOption, ExtendsLaravelCommand;
protected static function getTenantCommandName(): string
{
return 'tenants:rollback';
}
/**
* The console command description.
*
* @var string
*/
protected $description = 'Rollback migrations for tenant(s).';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct(Migrator $migrator)
{
parent::__construct($migrator);
@ -40,10 +24,7 @@ class Rollback extends RollbackCommand
$this->specifyTenantSignature();
}
/**
* Execute the console command.
*/
public function handle()
public function handle(): int
{
foreach (config('tenancy.migration_parameters') as $parameter => $value) {
if (! $this->input->hasParameterOption($parameter)) {
@ -52,7 +33,7 @@ class Rollback extends RollbackCommand
}
if (! $this->confirmToProceed()) {
return;
return 1;
}
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
@ -65,5 +46,12 @@ class Rollback extends RollbackCommand
event(new DatabaseRolledBack($tenant));
});
return 0;
}
protected static function getTenantCommandName(): string
{
return 'tenants:rollback';
}
}

View file

@ -11,27 +11,14 @@ use Symfony\Component\Console\Output\ConsoleOutput;
class Run extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Run a command for tenant(s)';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'tenants:run {commandname : The artisan command.}
{--tenants=* : The tenant(s) to run the command for. Default: all}';
/**
* Execute the console command.
*/
public function handle()
public function handle(): void
{
$argvInput = $this->ArgvInput();
$argvInput = $this->argvInput();
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) use ($argvInput) {
$this->line("Tenant: {$tenant->getTenantKey()}");
@ -41,10 +28,7 @@ class Run extends Command
});
}
/**
* Get command as ArgvInput instance.
*/
protected function ArgvInput(): ArgvInput
protected function argvInput(): ArgvInput
{
// Convert string command to array
$subCommand = explode(' ', $this->argument('commandname'));

View file

@ -14,29 +14,16 @@ class Seed extends SeedCommand
{
use HasATenantsOption;
/**
* The console command description.
*
* @var string
*/
protected $description = 'Seed tenant database(s).';
protected $name = 'tenants:seed';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct(ConnectionResolverInterface $resolver)
{
parent::__construct($resolver);
}
/**
* Execute the console command.
*/
public function handle()
public function handle(): int
{
foreach (config('tenancy.seeder_parameters') as $parameter => $value) {
if (! $this->input->hasParameterOption($parameter)) {
@ -45,7 +32,7 @@ class Seed extends SeedCommand
}
if (! $this->confirmToProceed()) {
return;
return 1;
}
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
@ -58,5 +45,7 @@ class Seed extends SeedCommand
event(new DatabaseSeeded($tenant));
});
return 0;
}
}

View file

@ -9,24 +9,11 @@ use Stancl\Tenancy\Contracts\Tenant;
class TenantList extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'tenants:list';
/**
* The console command description.
*
* @var string
*/
protected $description = 'List tenants.';
/**
* Execute the console command.
*/
public function handle()
public function handle(): void
{
$this->info('Listing all tenants.');
tenancy()