Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 9.6.0: Command tenants:migrate is not detected correctly #832

Closed
lbausch opened this issue Mar 29, 2022 · 7 comments · Fixed by #834
Closed

Laravel 9.6.0: Command tenants:migrate is not detected correctly #832

lbausch opened this issue Mar 29, 2022 · 7 comments · Fixed by #834
Assignees
Labels
bug Something isn't working

Comments

@lbausch
Copy link

lbausch commented Mar 29, 2022

Bug description

Laravel 9.6.0 introduced the method getDefaultName() in Illuminate\Console\Command with commit laravel/framework@628d39f

This method first tries to determine the command name from the signature property and - if not present - falls back to the name property.
Because Stancl\Tenancy\Commands\Migrate extends from Illuminate\Database\Console\Migrations\MigrateCommand the signature of this class (migrate) is inherited and used and not the defined name (tenants:migrate).

Steps to reproduce

Setup stancl/tenancy with Laravel 9.6.0

$ php artisan tenants:migrate -vvv       
Dropping tables.
Dropped all tables successfully.
Migrating.

In ArrayInput.php line 168:
                                                                
  [Symfony\Component\Console\Exception\InvalidOptionException]  
  The "--force" option does not exist.                          
                                                                

Exception trace:
  at /tmp/tenancy/vendor/symfony/console/Input/ArrayInput.php:168
 Symfony\Component\Console\Input\ArrayInput->addLongOption() at /tmp/tenancy/vendor/symfony/console/Input/ArrayInput.php:135
 Symfony\Component\Console\Input\ArrayInput->parse() at /tmp/tenancy/vendor/symfony/console/Input/Input.php:55
 Symfony\Component\Console\Input\Input->bind() at /tmp/tenancy/vendor/symfony/console/Command/Command.php:250
 Symfony\Component\Console\Command\Command->run() at /tmp/tenancy/vendor/laravel/framework/src/Illuminate/Console/Command.php:156
 Illuminate\Console\Command->run() at /tmp/tenancy/vendor/laravel/framework/src/Illuminate/Console/Concerns/CallsCommands.php:68
 Illuminate\Console\Command->runCommand() at /tmp/tenancy/vendor/laravel/framework/src/Illuminate/Console/Concerns/CallsCommands.php:40
 Illuminate\Console\Command->callSilent() at /tmp/tenancy/vendor/stancl/tenancy/src/Commands/MigrateFresh.php:49
 Stancl\Tenancy\Commands\MigrateFresh->Stancl\Tenancy\Commands\{closure}() at /tmp/tenancy/vendor/stancl/tenancy/src/Tenancy.php:160
 Stancl\Tenancy\Tenancy->runForMultiple() at /tmp/tenancy/vendor/stancl/tenancy/src/Commands/MigrateFresh.php:52
 Stancl\Tenancy\Commands\MigrateFresh->handle() at /tmp/tenancy/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:36
 Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() at /tmp/tenancy/vendor/laravel/framework/src/Illuminate/Container/Util.php:41
 Illuminate\Container\Util::unwrapIfClosure() at /tmp/tenancy/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:93
 Illuminate\Container\BoundMethod::callBoundMethod() at /tmp/tenancy/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:37
 Illuminate\Container\BoundMethod::call() at /tmp/tenancy/vendor/laravel/framework/src/Illuminate/Container/Container.php:653
 Illuminate\Container\Container->call() at /tmp/tenancy/vendor/laravel/framework/src/Illuminate/Console/Command.php:171
 Illuminate\Console\Command->execute() at /tmp/tenancy/vendor/symfony/console/Command/Command.php:291
 Symfony\Component\Console\Command\Command->run() at /tmp/tenancy/vendor/laravel/framework/src/Illuminate/Console/Command.php:156
 Illuminate\Console\Command->run() at /tmp/tenancy/vendor/symfony/console/Application.php:989
 Symfony\Component\Console\Application->doRunCommand() at /tmp/tenancy/vendor/symfony/console/Application.php:299
 Symfony\Component\Console\Application->doRun() at /tmp/tenancy/vendor/symfony/console/Application.php:171
 Symfony\Component\Console\Application->run() at /tmp/tenancy/vendor/laravel/framework/src/Illuminate/Console/Application.php:102
 Illuminate\Console\Application->run() at /tmp/tenancy/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:129
 Illuminate\Foundation\Console\Kernel->handle() at /tmp/tenancy/artisan:37

Expected behavior

Migrations for tenants should be run, no tables should be dropped.

Laravel version

9.6.0

stancl/tenancy version

3.5.3

@lbausch lbausch added the bug Something isn't working label Mar 29, 2022
@mreduar
Copy link

mreduar commented Mar 29, 2022

It also happens to me with Laravel 9.6
image

@stancl
Copy link
Member

stancl commented Mar 29, 2022

@lbausch Thanks for the comprehensive report! Would this issue be solved by explicitly providing the command name, e.g. via a $name property? (As used in laravel/framework@628d39f#diff-132f1c15b2ac9b4ff179e85239c0a55e0daead42be5a2095b0fe765d3bc9ebd0R105)

@lbausch
Copy link
Author

lbausch commented Mar 30, 2022

I wasn't able to get it working with a $name property. Looking at the code, a signature seems enough to make getDefaultName() return:

        $class = static::class;

        $signature = (new ReflectionClass($class))->getDefaultProperties()['signature'] ?? null;

        if (isset($signature)) {
            return Parser::parse($signature)[0];
        }

@vouala
Copy link

vouala commented Mar 30, 2022

I'm facing the same issue. Any suggestion to make it work and go on?

@stancl
Copy link
Member

stancl commented Mar 30, 2022

@vouala Lock Laravel to a previous version.

@lbausch I'd try to avoid overriding the signature since it includes the parameters as well, and we'd have to keep the command up to date with the parent Migrate command. But thanks for looking into that, I'll spend some time on it myself now.

@stancl
Copy link
Member

stancl commented Mar 30, 2022

Ah I see your point. The $signature already exists in the parent class.

@stancl stancl linked a pull request Mar 30, 2022 that will close this issue
@lbausch
Copy link
Author

lbausch commented Mar 30, 2022

Thank you @stancl! 💪🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants