BlackbitDigitalCommerce / pimcore-data-director

Import Bundle for Pimcore
16 stars 3 forks source link

Call to a member function getId() on null #152

Open betterapp opened 7 months ago

betterapp commented 7 months ago

We have a project that use third-party import/export solution When I installed DataDirector and use old import I get such error in logs:

app.ERROR: Error: Call to a member function getId() on null in /mnt/data/www/vendor/blackbit/data-director/EventListener/AutomaticImportListener.php:119 

Stack trace: 
#0 /mnt/data/www/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php(270): Blackbit\DataDirectorBundle\EventListener\AutomaticImportListener->startImports() 
#1 /mnt/data/www/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php(230): Symfony\Component\EventDispatcher\EventDispatcher::Symfony\Component\EventDispatcher\{closure}() 
#2 /mnt/data/www/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php(59): Symfony\Component\EventDispatcher\EventDispatcher->callListeners() 
#3 /mnt/data/www/vendor/pimcore/pimcore/models/DataObject/AbstractObject.php(767): Symfony\Component\EventDispatcher\EventDispatcher->dispatch() 
#4 /mnt/data/www/vendor/pimcore/pimcore/models/DataObject/Concrete.php(777): Pimcore\Model\DataObject\AbstractObject->save() 
#5 /mnt/data/www/bundles/ImportExportBundle/Command/BulkInsertCommand.php(392): Pimcore\Model\DataObject\Concrete->save() 
#6 /mnt/data/www/bundles/ImportExportBundle/Command/BulkInsertCommand.php(215): ImportExportBundle\Command\BulkInsertCommand->generateVersions() 
#7 /mnt/data/www/bundles/ImportExportBundle/Command/BulkInsertCommand.php(122): ImportExportBundle\Command\BulkInsertCommand->importXlsxData() 
#8 /mnt/data/www/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php(288): ImportExportBundle\Command\BulkInsertCommand->execute() 
#9 /mnt/data/www/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(992): Symfony\Component\Console\Command\Command->run() 
#10 /mnt/data/www/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php(96): Symfony\Component\Console\Application->doRunCommand() 
#11 /mnt/data/www/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(291): Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() 
#12 /mnt/data/www/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php(82): Symfony\Component\Console\Application->doRun() 
#13 /mnt/data/www/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(167): Symfony\Bundle\FrameworkBundle\Console\Application->doRun() 
#14 /mnt/data/www/bin/console(46): Symfony\Component\Console\Application->run() 
#15 {main} 

It should be checked if $object is empty then should not run command image

betterapp commented 7 months ago

@BlackbitDevs ??

BlackbitDevs commented 6 months ago

$object can only be null if the pimcore.dataobject.postUpdate or pimcore.dataobject.postAdd event gets called without an object. This sounds strange to me, especially because nowadays this is not even possible due to the return type of https://github.com/pimcore/pimcore/blob/177a8604c06831da6bb5889931342512659fef53/lib/Event/Model/ElementEventInterface.php#L23 But you are right that it should be checked if $object is an instance of ElementInterface, especially fpr Picmore versions where getElement() could return null.

Have fixed this in 3.6.6

Btw: Helper::getUser() will always return a user. If we cannot find a logged-in user, the system user gets returned.