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
Fixed the support of Legacy classes using Console commands #15081
Fixed the support of Legacy classes using Console commands #15081
Conversation
src/PrestaShopBundle/Resources/config/services/bundle/event_listener.yml
Outdated
Show resolved
Hide resolved
Hello @PrestaShop/prestashop-core-developers, any chance to get this merged in the next patch version? 🙏 When do you plan to release 1.7.6.1? |
I guess this is @eternoendless decision but if we follow our rules, this is neither a regression nor a critical bug 🤔 so it's not something we need to patch (=> would be shipped in a patch version), it's rather a nice improvement for next minor version
We have only 1 issue in the 1.7.6 kanban (https://github.com/PrestaShop/PrestaShop/projects/4) so once the Kanban is empty (= every issue is in "done" column), we can process for the QA validation and then the release. |
$this->legacyContext = $legacyContext; | ||
$this->shopContext = $shopContext; | ||
|
||
require_once $rootDir . '/../config/config.inc.php'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be used for a LFI, please add a validation here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you mean, validate that $rootDir will be a folder? in all cases, this file path will be dynamic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe better to change this line https://github.com/PrestaShop/PrestaShop/blob/develop/autoload.php#L31 in config.inc.php to load the legacy context because of this https://github.com/PrestaShop/PrestaShop/blob/develop/bin/console#L16
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @PierreRambaud, I see what you mean but IMHO the comment on the related file ("Allow call of Legacy classes from classes in /src and /tests") doesn't work as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is why it could be interesting to change the line and make it works
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure of the impacts as this file is also used in all contexts, I'd razer not rely on it and focus on what we need when we are in Console context.
How about a new file named autoload.php in console folder instead ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is only loaded in admin-dev/index.php
and ./bin/console
.
No need to create a new one to do the job its must do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that the thing: I don't think we should use this file at all in Console context: I will remove this call and see what happens :)
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function loadConsoleContext(InputInterface $input) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is InputInterface
the right input arg for this command ? It looks like using HttpRequest
as an input to me 🤔 maybe we should replace it with
public function loadConsoleContext(InputInterface $input) | |
public function loadConsoleContext($employeeId, $shopId, $shopGroupdId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I need to add a new option I will have to break compatibility, and if I use scalar values I will have to validate data in this function when it's not its role (these options should be validated in the "interact" function of the commands.
$inputDefinition = $this->getDefinition(); | ||
$inputDefinition->addOption(new InputOption('employee', '-em', InputOption::VALUE_REQUIRED, 'Specify employee context (id).', null)); | ||
|
||
// @see MultiShopCommandListener BC compatible fix to display the options in the Console |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's nice you're trying to solve all issues at once 😄 but I think it's a big challenge
Maybe we should aim to fix the different contexts in the console with different PRs ? I suggest handling the multishop in a separate PR, I'm sure it's a little bomb 💣 that will require a lot of efforts to tackle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it doesn't support multishop feature per see, it only displays the available options for each command :)
it's up to every command to handle or not these options ('id_shop' and 'id_shop_group') and it's probably a little 💣 I do agree
$this->setVersion(AppKernel::VERSION); | ||
|
||
$inputDefinition = $this->getDefinition(); | ||
$inputDefinition->addOption(new InputOption('employee', '-em', InputOption::VALUE_REQUIRED, 'Specify employee context (id).', null)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only needed for BO, what if the CLI is used for a FO-related processing ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking that maybe we should aim for BO-oriented CLI console and then a FO-oriented CLI console (separate concerns => separate envs) 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
except if I'm wrong you always have an employee set up, even in the Front Office :)
What kind of commands I can create that requires services available in FO?
Also, don't be fooled by the REQUIRED stuff: a CLI option is always optional 🤣
We need to cover more use cases, and I've already created 3 different commands in my module.
* | ||
* @author Mickaël Andrieu <mickael.andrieu@prestashop.com> | ||
*/ | ||
abstract class Command extends ContainerAwareCommand |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we improve the naming ? Command
is a bit shy to express the fact that this is a "Symfony Command class for PrestaShop allowed to rely on legacy classes"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I formerly named it "PrestaShopCommand", but as this class is part of PrestaShop only; I don't see the value to prefix the name of my class with PrestaShop.
I'm open to suggestions, what do you suggest?
@mickaelandrieu did a small review, it's great to see there's not so much to be done to fix the issue but I think it'll need extensive QA exploration for complex usecases like multishop Nice job ! I did something a lot of time ago, dont know if it's related: I tried to make sure every SF Service we create is console-compliant |
What we can do is add an extra validation pass to forbid every class that is not "namespaced" as an argument of a Symfony service: we should only rely on adapters or core classes. Also, clean all core/prestashop classes to drop every "direct" call to object models: it's not that easy to do but in the long run, this will help you to remove object models (if you intent to ?). Second extra rule, don't rely directly on the global state like "context" or "request". This patch sounds complete, but I'm pretty sure such hacky use cases are not covered: I want to write more and more commands to try to break something 🗡 💥 |
ping @matks: looking at your PR I've contributed my own command to challenge the Console Context. I've found some misses that I've fixed for now but I'll do it a better way soon. As this won't be merged in 1.7.6.1 I'll Thanks for your review, literally food for my brain 👍 |
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function checkAccess() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are targeting 7.1+ you can type all your functions and parameters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly, doing this will break the API as the former controller I extend doesn't type functions or arguments
Tests are here, I can add a lot of tests commands from my own module (that allow people to enjoy this feature starting 1.7.4 or 5). WDYT? |
*/ | ||
protected function buildContainer() | ||
{ | ||
return SymfonyContainer::getInstance(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function is not used atm, but as the parent function is supposed to return a Container...
Tests have been added 👍 , it's not in WIP anymore! |
bin/console
Outdated
@@ -12,8 +12,8 @@ use Symfony\Component\Debug\Debug; | |||
|
|||
set_time_limit(0); | |||
|
|||
require __DIR__.'/../vendor/autoload.php'; | |||
require_once __DIR__.'/../autoload.php'; | |||
require_once __DIR__.'/../vendor/autoload.php'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
require_once __DIR__.'/../vendor/autoload.php'; |
Already loaded in config.inc.php
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know but without it, I have the feeling it won't works.
Let me remove it and let's see if this file is required or not :)
@@ -6,7 +6,7 @@ services: | |||
|
|||
prestashop.adapter.cms_page_category.command_handler.abstract_cms_page_category_handler: | |||
class: PrestaShop\PrestaShop\Adapter\CMS\PageCategory\CommandHandler\AbstractCmsPageCategoryHandler | |||
abstract: true | |||
abstract: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
abstract: true | |
abstract: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this file is not supposed to be there , i'll remove it
Hi @PierreRambaud, comments addressed. Thanks for review
|
:/ I had to restore this branch as #14173 is not fixed, but I wont have time to update/maintain it. |
This change is