naf4me naf4me - 5 months ago 77
PHP Question

Remove old artisan command by new artisan command in laravel 5.2 kernel console

I am working in kernel command where I need to change the old commands:

Old Command is:

php artisan crawl:author


Now I need to rename it like:

php artisan crawl-bq:author


In my command file signature is changed like:

protected $signature = 'crawl-bq:author';

I cleaned the artisan cache using following command:

php artisan cache:clear
php artisan config:cache


Still my old command is working as well as new command is also working. But when I see the artisan list "php artisan list" then old commands are not seen there also.

Anybody there to help me?

Answer

After a long time, I have come to state where I have found that Laravel 5.2 artisan console command has a bug or it is not bug as at least one command will be executed according to initial pattern matching.

Let assume, you have two signatures in two different command file like following 4 cases:

Case I:

protected $signature = 'crawl:author-usa';
protected $signature = 'crawl:author-uk';

OR Case II:

protected $signature = 'crawl:authorusa';
protected $signature = 'crawl:authoruk';

OR Case III:

protected $signature = 'crawl-bq:author-usa';
protected $signature = 'crawl-bq:author-uk';

OR Case IV:

protected $signature = 'crawl-bq:authorusa';
protected $signature = 'crawl-bq:authoruk';

For either case, if you run the php artisan crawl:auther command then for Case I, it will show the ambiguous error like:

[Symfony\Component\Console\Exception\CommandNotFoundException] Command "crawl:author" is ambiguous (crawl:author-usa, crawl:author-uk).

It will show the same ambiguous message for the rest 3 cases but signature wise text would be different.

Now assume the following signature for 4 different cases:

Case I:

protected $signature = 'crawl:author-usa';

OR Case II:

protected $signature = 'crawl:authorusa';

OR Case III:

protected $signature = 'crawl-bq:author-usa';

OR Case IV:

protected $signature = 'crawl-bq:authorusa';

For either case, if you run the php artisan crawl:auther command, it will execute that command.

For these two scenario, it is happening because of Symfony/Cconsole find() function. Here exact command is searched by this expression : crawl[^:]*[^:]*:author[^:]*[^:]* . That means, if any signature has crawl<anything>:author<anything> will match with php artisan crawl:author

Now if I come to the solution of this problem, primarily it needs to change public function find($name) near 509 line at symfony/consle file. Or if there is a possibility to overwrite this function ( I am not sure how this override could be done ).

I was inspired by @Nadeem0035 where he mentioned the public function find($name) near 509 line at symfony/consle file. I would have been happy if I could award the bounty in bounty time duration as at least he showed me a way to find exact scenario of console command. That is why a up vote dude :)

Comments