Prestashop: Impossible to load Legacy classes in Console commands

Created on 12 Jun 2019  路  10Comments  路  Source: PrestaShop/PrestaShop

Description of the limitation

If a Command attempts to use legacy classes, it will crash because legacy class expect multiple items to be initialized before, such as an employee, a context, a controller.

Example: try to add this Command to your PS and run it

<?php

namespace PrestaShopBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class TestConsoleCommand extends ContainerAwareCommand
{
    public function configure()
    {
        $this
            ->setName('prestashop:test-console')
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $products = \Product::getNewProducts(1);
    }
}
1.7.5.x Bug Developer Feature PR available migration

All 10 comments

ping @PrestaShop/prestashop-core-developers what do you think? what is the severity of this issue?

Thanks!

It's probably a bootstrapping issue. Needs to be investigated so that PrestaShop is correctly initialized when launching module commands. I suppose that this is not a problem when using Core sf commands?

FYI It's fixed in 1.7.6.2

Reopening the issue as it's still there

I'll deal with it

@mickaelandrieu Feel free to remove notification on the right panel, with this, you'll no longer receive notifications :+1:
image

Done !

Spent a lot of time today trying to fix this without modifying Command and Application classes to avoid BC break.
My idea is to use Console Command events, plug myself "just before any command is run" and load the fake context.

However this has to be done after container is booted. So I need to plug myself

  • after $kernel->boot(); (so container is available)
  • before doRun()

and the 2 happens at same time in FrameworkBundle/Console/Application

    public function doRun(InputInterface $input, OutputInterface $output)
    {
        $this->kernel->boot();

        $this->setDispatcher($this->kernel->getContainer()->get('event_dispatcher'));

        $this->registerCommands();

        if ($this->registrationErrors) {
            $this->renderRegistrationErrors($input, $output);
        }

        return parent::doRun($input, $output);
    }

I also found some limitation that I reported to Symfony https://github.com/symfony/symfony/issues/37680

Or ... you could have accepted the PR I've done months ago, fix, tests and module included 馃お

Believe me or not, even after clicking on "Unsubscribe" I'm still notified both per email and on the website :/

Believe me or not, even after clicking on "Unsubscribe" I'm still notified both per email and on the website :/

This looks like a GitHub issue. You might want to report it. Lately they have shipped a lot of features and improvements, it seems they can fix things fast.

Was this page helpful?
0 / 5 - 0 ratings