View Issue Details

IDProjectCategoryView StatusLast Update
0007365OXID eShop (all versions)2.3. Extensions (modules, themes)public2022-11-10 10:11
Reportermichael_keiluweit 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version6.5.0 
Target VersionFixed in VersionNext Major Version 
Summary0007365: Shop aware console command breaks if SymfonyS DI container creates the cache file
DescriptionIf the file container_cache.php is created by Symfony's DI container without any adaption of the shop framework, then shop aware console commands can produce an error

A shop aware console command gets the entry "instance->setActiveShops()" in the cache file container_cache.php. This entry is made during the activation process of a module by the method activateModuleService -> addActiveShops -> addShopAwareCallsIfMissing.

If the Symfony's DI container creates the file (because the file the was deleted earlier, it's a temporary-files-directory after all) then the shop aware entry for the console command is not made properly and leads to the error "OXID Logger.ERROR: Call to a member function getCurrentShopId() on null".

This happens if a module is required via composer and activated via the console but the file container_cache.php does no exist.
The DI container is checking if the file container_cache.php exists. If not, it will be created by Symfony's DI container. After that the module activation process gets started, but the cache's entry is lacking information and this finally leads to the error.
Steps To Reproduce1) Install the latest shop
2) composer config minimum-stability dev
3) git clone https://github.com/oxid-support/t110285
4) composer config repositories.oxid-support/command path t110285/oxs/command
5) composer require oxid-support/command
6) rm -rf source/tmp/*
7) ./vendor/bin/oe-console oe:module:activate oxscommand
8) ./vendor/bin/oe-console (simulate using other console commands)


Until now everything works fine. Imagine the module got an update and the update needs to get installed.


1) Copy the file t110285/oxs/command/CountCommand2.php to t110285/oxs/command/CountCommand3.php
2) Replace the 2 with 3 inside the file
  - class CountCommand2 -> class CountCommand3
  - ->setName('oxs:product-counter:count2') -> ->setName('oxs:product-counter:count3')
3) Add a new entry in t110285/oxs/command/services.yaml
      OxidSupport\Command\CountCommand3:
        autowire: true
        tags:
        - { name: 'console.command', command: 'oxs:product-counter:count3'}
4) composer require oxid-support/command (Keep in mind to choose "y" when it asks you to the copy the files "Update operation will overwrite oxid-support/command files".
5) rm -rf source/tmp/*
6) ./vendor/bin/oe-console (simulate using other console commands)

The last command is not executed properly and you will find a new entry in source/log/oxideshop.log:

Stacktrace -> see comments https://bugs.oxid-esales.com/view.php?id=7365#c14510 (somehow isn't allowed in the entry).
Additional InformationExpected:
protected function getCountCommand2Service()
{
    $this->privates['OxidSupport\\Command\\CountCommand2'] = $instance = new \OxidSupport\Command\CountCommand2(($this->privates['OxidSupport\\Command\\Counter'] ?? $this->getCounterService()));

    $instance->setActiveShops([0 => 1]);
    $instance->setContext(($this->services['OxidEsales\\EshopCommunity\\Internal\\Transition\\Utility\\ContextInterface'] ?? ($this->services['OxidEsales\\EshopCommunity\\Internal\\Transition\\Utility\\ContextInterface'] = new \OxidEsales\EshopCommunity\Internal\Transition\Utility\Context())));
    $instance->setName('oxs:product-counter:count2');

    return $instance;
}

Actual (Don't mind the Command2 and Command3. Command3 should exactly look like Command2):
protected function getCountCommand3Service()
{
    $this->privates['OxidSupport\\Command\\CountCommand3'] = $instance = new \OxidSupport\Command\CountCommand3(($this->privates['OxidSupport\\Command\\Counter'] ?? $this->getCounterService()));

    $instance->setName('oxs:product-counter:count3');

    return $instance;
}




Workaround:
(Re-)activate the module via the administration area. By this, the necessary entries are written into the file container_cache.php.
TagsDI, Module
ThemeNot defined
BrowserNot defined
PHP VersionNot defined
Database VersionNot defined

Relationships

related to 0007301 resolvedvasyl.liulka It's not possible to import services.yaml files within a module 

Activities

michael_keiluweit

2022-10-18 14:44

administrator   ~0014510

[2022-10-18 14:24:36] OXID Logger.ERROR: Call to a member function getCurrentShopId() on null ["[object] (Error(code: 0): Call to a member function getCurrentShopId() on null at /var/www/oxideshop/vendor/oxid-esales/oxideshop-ce/source/Internal/Framework/Event/ShopAwareServiceTrait.php:59)\n[stacktrace]\n#0 /var/www/oxideshop/vendor/oxid-esales/oxideshop-ce/source/Internal/Framework/Console/CommandsProvider/ServicesCommandsProvider.php(77): OxidEsales\\EshopCommunity\\Internal\\Framework\\Console\\AbstractShopAwareCommand->isActive()\n#1 /var/www/oxideshop/vendor/oxid-esales/oxideshop-ce/source/Internal/Framework/Console/CommandsProvider/ServicesCommandsProvider.php(53): OxidEsales\\EshopCommunity\\Internal\\Framework\\Console\\CommandsProvider\\ServicesCommandsProvider->setShopAwareCommands(Object(OxidSupport\\Command\\CountCommand3))\n#2 /var/www/oxideshop/vendor/oxid-esales/oxideshop-ce/source/Internal/Framework/Console/CommandsProvider/ServicesCommandsProvider.php(41): OxidEsales\\EshopCommunity\\Internal\\Framework\\Console\\CommandsProvider\\ServicesCommandsProvider->addLazyLoadedCommands()\n#3 /var/www/oxideshop/vendor/oxid-esales/oxideshop-ee/Internal/Framework/Console/Executor.php(75): OxidEsales\\EshopCommunity\\Internal\\Framework\\Console\\CommandsProvider\\ServicesCommandsProvider->getCommands()\n#4 /var/www/oxideshop/vendor/oxid-esales/oxideshop-ce/bin/oe-console(43): OxidEsales\\EshopEnterprise\\Internal\\Framework\\Console\\Executor->execute()\n#5 /var/www/oxideshop/vendor/bin/oe-console(120): include('/var/www/oxides...')\n#6 {main}\n"] []
[18 Oct 14:24:36.947902 2022] [uncaught error] [type E_ERROR] [file /var/www/oxideshop/vendor/oxid-esales/oxideshop-ce/source/Internal/Framework/Event/ShopAwareServiceTrait.php] [line 59] [code ] [message Uncaught Error: Call to a member function getCurrentShopId() on null in /var/www/oxideshop/vendor/oxid-esales/oxideshop-ce/source/Internal/Framework/Event/ShopAwareServiceTrait.php:59
Stack trace:
#0 /var/www/oxideshop/vendor/oxid-esales/oxideshop-ce/source/Internal/Framework/Console/CommandsProvider/ServicesCommandsProvider.php(77): OxidEsales\EshopCommunity\Internal\Framework\Console\AbstractShopAwareCommand->isActive()
#1 /var/www/oxideshop/vendor/oxid-esales/oxideshop-ce/source/Internal/Framework/Console/CommandsProvider/ServicesCommandsProvider.php(53): OxidEsales\EshopCommunity\Internal\Framework\Console\CommandsProvider\ServicesCommandsProvider->setShopAwareCommands(Object(OxidSupport\Command\CountCommand3))
#2 /var/www/oxideshop/vendor/oxid-esales/oxideshop-ce/source/Internal/Framework/Console/CommandsProvider/ServicesCommandsProvider.php(41): OxidEsales\EshopCommunity\Internal\Framework\Console\CommandsProvider\ServicesCommandsProvider->addLazyLoadedCommands()
#3 /var/www/oxideshop/vendor/oxid-esales/oxideshop-ee/Internal/Framework/Console/Executor.php(75): OxidEsales\EshopCommunity\Internal\Framework\Console\CommandsProvider\ServicesCommandsProvider->getCommands()
#4 /var/www/oxideshop/vendor/oxid-esales/oxideshop-ce/bin/oe-console(43): OxidEsales\EshopEnterprise\Internal\Framework\Console\Executor->execute()
#5 /var/www/oxideshop/vendor/bin/oe-console(120): include('/var/www/oxides...')
#6 {main}
  thrown]

QA

2022-10-19 15:02

administrator   ~0014513

Last edited: 2022-10-19 15:06

View 2 revisions

When deactivating the module before the update, the procedure works fine in my tests. Usually we recommend to deactivate all modules on shop updates and I also suggest to deactivate the specific module before updating this package. The (re-)activation of the module is needed to write the necessary data to the generated_services.yaml. If this file is correct, the container_cache.php file is also generated correctly. That's also the reason why it works after reactivation via administration area. You can also simulate this by removing one entry - e.g. OxidSupport\Command\CountCommand2 - from the generated_services.yaml file, clearing the cache and run vendor/bin/oe-console again to regenerate the container_cache.php file. Then the instance->setActiveShops and $instance->setContext() entries are also missing in container_cache.php for OxidSupport\Command\CountCommand2.

Reactivating the module via OE Console after update is not possible due to the corrupted container_cache.php file, which the OE Console uses. The administration area seems not to use/need this. The different behavior of administration area and OE Console is not an ideal situation and therefore I acknowledge the issue. Also we may add a manual to our documentation describing a clean way of updating modules.

[sp]