mirror of
https://github.com/archtechx/tenancy.git
synced 2026-08-06 05:54:03 +00:00
- We conditionally use either $signature + specifyParameters() in the newer versions or just $name in the older versions. There doesn't appear to be a single solution that'd work in both versions, likely having to do with the constructor override in the trait and how the specifyParameters() method behaves differently in this class between versions - Remove unnecessary options from the Run command (the trait adds those) - Not directly related: make HasTenantOptions accept ...$args - Unrelated: remove phpstan ignore in TenancyServiceProvider
61 lines
1.8 KiB
PHP
61 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Stancl\Tenancy\Commands;
|
|
|
|
use Illuminate\Database\ConnectionResolverInterface;
|
|
use Illuminate\Database\Console\Seeds\SeedCommand;
|
|
use Stancl\Tenancy\Concerns\HasTenantOptions;
|
|
use Stancl\Tenancy\Events\DatabaseSeeded;
|
|
use Stancl\Tenancy\Events\SeedingDatabase;
|
|
|
|
class Seed extends SeedCommand
|
|
{
|
|
use HasTenantOptions;
|
|
|
|
protected $description = 'Seed tenant database(s).';
|
|
|
|
public function __construct(ConnectionResolverInterface $resolver)
|
|
{
|
|
// See https://github.com/archtechx/tenancy/issues/1474
|
|
if (version_compare(app()->version(), '13.24.0', '>=')) {
|
|
$this->signature = 'tenants:seed
|
|
{class? : The class name of the root seeder}
|
|
{--class=Database\\Seeders\\DatabaseSeeder : The class name of the root seeder}
|
|
{--database= : The database connection to seed}
|
|
{--force : Force the operation to run when in production}';
|
|
parent::__construct($resolver);
|
|
$this->specifyParameters();
|
|
} else {
|
|
$this->name = 'tenants:seed';
|
|
parent::__construct($resolver);
|
|
}
|
|
}
|
|
|
|
public function handle(): int
|
|
{
|
|
foreach (config('tenancy.seeder_parameters') as $parameter => $value) {
|
|
if (! $this->input->hasParameterOption($parameter)) {
|
|
$this->input->setOption(ltrim($parameter, '-'), $value);
|
|
}
|
|
}
|
|
|
|
if (! $this->confirmToProceed()) {
|
|
return 1;
|
|
}
|
|
|
|
tenancy()->runForMultiple($this->getTenants(), function ($tenant) {
|
|
$this->components->info("Tenant: {$tenant->getTenantKey()}");
|
|
|
|
event(new SeedingDatabase($tenant));
|
|
|
|
// Seed
|
|
parent::handle();
|
|
|
|
event(new DatabaseSeeded($tenant));
|
|
});
|
|
|
|
return 0;
|
|
}
|
|
}
|