pim-community-dev icon indicating copy to clipboard operation
pim-community-dev copied to clipboard

RemoveNonExistingProductValuesSubscriber requires a logged in user

Open jannes-io opened this issue 2 years ago • 1 comments

:bug: I'm reporting a Bug :bug:

Context: When trying to create/delete attribute options from a CLI or testing context an error is thrown.

[Error] Call to a member function getUser() on null

#1  /var/www/html/vendor/akeneo/pim-community-dev/src/Akeneo/Pim/Structure/Bundle/EventListener/RemoveNonExistingProductValuesSubscriber.php:71
#2  /var/www/html/vendor/symfony/event-dispatcher/Debug/WrappedListener.php:117
#3  /var/www/html/vendor/symfony/event-dispatcher/EventDispatcher.php:230
#4  /var/www/html/vendor/symfony/event-dispatcher/EventDispatcher.php:59
#5  /var/www/html/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:154

Cause

RemoveNonExistingProductValuesSubscriber::launchRemoveNonExistingProductValuesJob requires a user to be logged in.

TokenStorageInterface::getToken can return null. This is not handled properly.

JobLauncherInterface::launch is designed to work with null for $user.

Fix On RemoveNonExistingProductValuesSubscriber:71 allow null

- $user = $this->tokenStorage->getToken()->getUser();
+ $user = $this->tokenStorage->getToken()?->getUser();

Will create a pull request.

jannes-io avatar Jan 27 '23 14:01 jannes-io

Any update on this?

svdv22 avatar Dec 12 '23 12:12 svdv22