mirror of
https://github.com/archtechx/tenancy.git
synced 2026-08-06 23:14:04 +00:00
Fix tenants:seed command name via configure() (#1474)
Replaces the version_compare hack with a configure() override that sets the command name, which works regardless of whether the installed Laravel version's SeedCommand uses $name or $signature.
This commit is contained in:
parent
e0990a438c
commit
d2c96bb913
1 changed files with 18 additions and 11 deletions
|
|
@ -18,21 +18,28 @@ class Seed extends SeedCommand
|
||||||
|
|
||||||
public function __construct(ConnectionResolverInterface $resolver)
|
public function __construct(ConnectionResolverInterface $resolver)
|
||||||
{
|
{
|
||||||
// See https://github.com/archtechx/tenancy/issues/1474
|
parent::__construct($resolver);
|
||||||
if (version_compare(app()->version(), '13.24.0', '>=')) {
|
|
||||||
$this->signature = 'tenants:seed
|
// Our --tenants/--skip-tenants/--with-pending options only get added automatically
|
||||||
{class? : The class name of the root seeder}
|
// when the parent command isn't signature-based. Since Laravel 13.24, SeedCommand is,
|
||||||
{--class=Database\\Seeders\\DatabaseSeeder : The class name of the root seeder}
|
// so we add them ourselves here -- checking first so we don't add them twice on older
|
||||||
{--database= : The database connection to seed}
|
// Laravel versions, where they're already there by this point.
|
||||||
{--force : Force the operation to run when in production}';
|
if (! $this->getDefinition()->hasOption('tenants')) {
|
||||||
parent::__construct($resolver);
|
|
||||||
$this->specifyParameters();
|
$this->specifyParameters();
|
||||||
} else {
|
|
||||||
$this->name = 'tenants:seed';
|
|
||||||
parent::__construct($resolver);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function configure(): void
|
||||||
|
{
|
||||||
|
parent::configure();
|
||||||
|
|
||||||
|
// We inherit SeedCommand's name ('db:seed') since we don't redeclare $name/$signature,
|
||||||
|
// so without this we'd overwrite Laravel's own db:seed command (see #1474). configure()
|
||||||
|
// always runs after the name is set, regardless of Laravel version, so setting it here
|
||||||
|
// is safe no matter which of $name/$signature the installed Laravel version uses.
|
||||||
|
$this->setName('tenants:seed');
|
||||||
|
}
|
||||||
|
|
||||||
public function handle(): int
|
public function handle(): int
|
||||||
{
|
{
|
||||||
foreach (config('tenancy.seeder_parameters') as $parameter => $value) {
|
foreach (config('tenancy.seeder_parameters') as $parameter => $value) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue