6
votes

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?

4
Have you removed the command in app\Console\Kernel.php? Maybe try: php composer dump-autoload.Thomas Van der Veen
@ThomasVanderVeen Yes, and I ran this command php composer dump-autoload couple of times. Even I set the project up couple of times by deleting vendor folder. That means I had to run composer update and composer dump-autoload.naf4me
why don't you use an editor that has a global search feature and search your project for 'scrape:category' you probably have a remnant of it somewheretam5
@tam I did it already but no reference I got for the old.naf4me
does artisan clear-compiled change anything?lagbox

4 Answers

1
votes

Old Command is:

php artisan crawl:author

Now we rename it like "crawl-bq:author"

php artisan crawl-bq:author (Will Work)
php artisan crawl-b:author (Will Work)
php artisan craw:author (Will Work)
php artisan crawl:author (Will Work)

Solution

Rename it with some other name like "newcrawl-bq:author"

php artisan crawl:author (Not work)
php artisan crawl-bq:author (Not work)
php artisan newcrawl-bq:author (Will work)
1
votes

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 :)

0
votes

I replicated all the steps you mentioned and I have no problem changing signatures - Laravel doesn't seem to include artisan commands into config cache, or anywhere else for that matter. Composer dump-autoload is not relevant here if filenames remained unchanged.

The only advice I can give is to check Console/Kernel.php $commands to make sure that no duplicate commands are loaded and all signatures are as they should be. Maybe some other command is still implementing the old signature?

I realise this is an old question. Maybe you managed to solve this issue already?

0
votes

you need to remove the old command file from app/Console/Commands/

and this should work.