Alex
Alex

Reputation: 34978

After upgrade from Shopware 5.6.10->5.7.6, custom console commands are missing

We upgraded a Shopware 5 system for testing from 5.6.10 to 5.7.6

Now the console command

hpr:orders:export  

is missing.

This is from a marketplace module which is no longer officially supported - the question is if there is an easy way to patch it.

Old installation:

php7.2 ./console |grep hpr
 hpr
  hpr:orders:export                          Starting the export (as defined in the plugin-config) of the orders. Options are mostly the same as the REST-API options.

After Upgrade:

 php7.4 ./console |grep hpr
 (no output)

In the upgrade guide for 5.7, it states that Symfony was upgraded ... but no breaking changes concerning this are mentioned directly.

namespace HPrAutomaticOrderExport\Components;

use Exception;
use Shopware\Commands\ShopwareCommand;
use Shopware\Components\Plugin\ConfigReader;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class CLICommand extends ShopwareCommand
{


    protected function configure()
    {
    $this->setName('hpr:orders:export');
    $this->setDescription('Starting the export (as defined in the plugin-config) of the orders. Options are mostly the same as the REST-API options.');
    $this->addOption('states', null, InputOption::VALUE_OPTIONAL, 'coma seperated list of order-states ids to filter output');
    $this->addOption('statespayment', null, InputOption::VALUE_OPTIONAL, 'coma seperated list of payment-states ids to filter output');
    $this->addOption('range', null, InputOption::VALUE_OPTIONAL, 'date range: startdate,enddate'); //TODO syntax for today - n days would be great!!!!!!
    $this->addOption('start', null, InputOption::VALUE_OPTIONAL, 'start index in list of orders (defaukt is 0, beginning of the list)');
    $this->addOption('limit', null, InputOption::VALUE_OPTIONAL, 'maximal count of orders to export (default is 100)');
    $this->addOption('number', null, InputOption::VALUE_OPTIONAL, 'number of a single order');
    $this->addOption('exportall', null, InputOption::VALUE_OPTIONAL, 'export all orders, ignore states');
    }

The plugin is enabled:

 php7.4 console sw:plugin:list|grep Order
 | HPrAutomaticOrderExport             | Automatic XML Order-Export Standard                                        
 | 3.7.1   | Windeit Software GmbH    | Yes    | Yes       |

services.xml EDIT

    <service id="hp_order_export_command" class="HPrAutomaticOrderExport\Components\CLICommand">
        <tag name="console.command" />
        <argument type="service" id="shopware.plugin.config_reader"/>
        <argument type="service" id="hp_order_export_service"/>
    </service>

UPDATE We just disabled the plugin, because we don't really need it - I still leave this open for further readers.

Upvotes: 2

Views: 513

Answers (4)

Kamas
Kamas

Reputation: 21

The best way is mentioned here: https://symfony.com/doc/4.4/console/commands_as_services.html

With Shopware 5.7 update, your symfony version is now on 4.4. So you have the possiblity to set name command names as protected static privates.

At this moment I am migrating a Shopware project from 5.6 to 5.7 and had same issues like you.

This worked for my command-classes, remove this:

protected function configure(): void {
   $this->setName('namespace:mycommandname');

PS: You can leave your setDescriptions or setHelp methods.

Then add following example from symfony help page:

class SunshineCommand extends Command
{
    protected static $defaultName = 'namespace:mycommandname';

Edit: Like @Torben says, you can also use command="namespace:mycommand" in services.xml. But for me, it is necessary to have access to constants in php-classes. I prevent using services.xml for special cases.

Upvotes: 2

Torben
Torben

Reputation: 5494

@Alex

I have the same issue with upgrading SW 5.6 to SW 5.7 and therefore to Symfony 4.4.

I see that suddenly commands are not visible anymore and I need to lazy load them instead of doing this:

<tag name="console.command" />

I now have to do this:

<tag name="console.command" command="netcom:migrations:migrate:up" />

What I do not understand is, the "normal" way of tagging them without lazy loading must also be possible, must it? Or do I always have to mark console commands as being lazy loaded? That is unclear to me currently... because I think the docs state these two options here and that lazy loading has performance gains: https://symfony.com/doc/4.4/console/commands_as_services.html

Upvotes: 1

Michael Werschnik
Michael Werschnik

Reputation: 11

I also had some problems with this plugin after upgrading to Shopware 5.7.x.

in my case it was

"The "hp_order_export_service" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead."

I added in custom/plugins/HPrAutomaticOrderExport/Resources/services.xml under <services> the line <defaults public="true"/>

that helped, maybe it will help others too.

Upvotes: 1

Alex
Alex

Reputation: 34978

Based on Michael T's comment:

After changing the tag to

<tag name="console.command" value="hpr:orders:export"/>

and cache flush the command is dispalyed in the console again.

Upvotes: 1

Related Questions