myparcelnl / prestashop

PrestaShop module to integrate with MyParcel NL and BE
https://developer.myparcel.nl/nl/documentatie/11.prestashop.html
10 stars 5 forks source link

[BETA]: installation error - Integrity constraint violation - hooks #248

Closed mariuszsienkiewicz closed 2 months ago

mariuszsienkiewicz commented 4 months ago

Version check

PrestaShop version

8.1.5

PHP version

8.1.28

What went wrong?

I have tried to test the myparcelnl on stock PrestaShop 8.1.5 installation.

There is an issue while trying to install the module for the first time. MyParcelNL\PrestaShop\Service\ModuleService registerHooks method is executed twice - in the install process and then in the enable() (MyParcelNL class) which causes integrity violuation error.

Log below.

Reproduction steps

  1. Install fresh PrestaShop.
  2. Install the module

Relevant log output

Error: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '68-961-1' for key 'PRIMARY'
Stack trace:
#0 <psroot>/classes/db/Db.php(377): DbPDOCore->_query()
#1 <psroot>/classes/db/Db.php(744): DbCore->query()
#2 <psroot>/classes/db/Db.php(477): DbCore->q()
#3 <psroot>/classes/Hook.php(619): DbCore->insert()
#4 <psroot>/classes/module/Module.php(1061): HookCore::registerHook()
#5 <psroot>/modules/myparcelnl/src/Service/ModuleService.php(35): ModuleCore->registerHook()
#6 <psroot>/modules/myparcelnl/vendor/myparcelnl/pdk/src/Base/Facade.php(25): MyParcelNL\PrestaShop\Service\ModuleService->registerHooks()
#7 <psroot>/modules/myparcelnl/src/Pdk/Installer/Service/PsInstallerService.php(90): MyParcelNL\Pdk\Base\Facade::__callStatic()
#8 <psroot>/modules/myparcelnl/vendor/myparcelnl/pdk/src/App/Installer/Service/InstallerService.php(52): MyParcelNL\PrestaShop\Pdk\Installer\Service\PsInstallerService->executeInstallation()
#9 <psroot>/modules/myparcelnl/src/Pdk/Installer/Service/PsInstallerService.php(57): MyParcelNL\Pdk\App\Installer\Service\InstallerService->install()
#10 <psroot>/modules/myparcelnl/vendor/myparcelnl/pdk/src/Base/Facade.php(25): MyParcelNL\PrestaShop\Pdk\Installer\Service\PsInstallerService->install()
#11 <psroot>/modules/myparcelnl/myparcelnl.php(101): MyParcelNL\Pdk\Base\Facade::__callStatic()
#12 <psroot>/modules/myparcelnl/myparcelnl.php(162): MyParcelNL->{closure}()
#13 <psroot>/modules/myparcelnl/myparcelnl.php(102): MyParcelNL->withErrorHandling()
#14 <psroot>/src/Adapter/Module/Module.php(271): MyParcelNL->install()
#15 <psroot>/src/Core/Module/ModuleManager.php(109): PrestaShop\PrestaShop\Adapter\Module\Module->onInstall()
#16 <psroot>/src/PrestaShopBundle/Controller/Admin/Improve/ModuleController.php(384): PrestaShop\PrestaShop\Core\Module\ModuleManager->install()
#17 <psroot>/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php(169): PrestaShopBundle\Controller\Admin\Improve\ModuleController->importModuleAction()
#18 <psroot>/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php(81): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#19 <psroot>/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(201): Symfony\Component\HttpKernel\HttpKernel->handle()
#20 <psroot>/admin-dev/index.php(84): Symfony\Component\HttpKernel\Kernel->handle()
#21 {main}

Additional context

No response

EdieLemoine commented 3 months ago

Hi @mariuszsienkiewicz and @pipo1000, thanks for reporting this.

We didn't run into this issue ourselves until I tried deleting everything and starting over from scratch... Now I get this error too on my development environment. Trying to install another time does not give me this error anymore, though.

We'll work on fixing this issue, but in the meantime, @pipo1000, I'm curious to know if trying the installation again works for you too.

pipo1000 commented 3 months ago

Hi @mariuszsienkiewicz and @pipo1000, thanks for reporting this.

We didn't run into this issue ourselves until I tried deleting everything and starting over from scratch... Now I get this error too on my development environment. Trying to install another time does not give me this error anymore, though.

We'll work on fixing this issue, but in the meantime, @pipo1000, I'm curious to know if trying the installation again works for you too.

When I create an new installation with the Docker Prestashop image, install the plugin, I get the exception, I remove the plugin, I install it again, and now the installation succeeded without an exception.

However, when I then try to enter my API key I get an error;

message An exception occurred while executing 'SELECT t0.carrier_id AS carrier_id_1, t0.myparcel_carrier AS myparcel_carrier_2, t0.date_upd AS date_upd_3, t0.date_add AS date_add_4 FROM ps_myparcelnl_carrier_mapping t0 WHERE t0.myparcel_carrier = ? LIMIT 1' with params ["postnl"]:\n\nSQLSTATE[42S02]: Base table or view not found: 1146 Table 'ps81empty.ps_myparcelnl_carrier_mapping' doesn't exist

Sadly the ps_myparcel* tables do not exist in my database. Deleting the plugin again with 'optional; remove the plugin directory' and installing it for the third time will create the tables.

However; now I get the following error when I try to add my API key;

An exception occurred while executing 'INSERT INTO ps_myparcelnl_carrier_mapping (carrier_id, myparcel_carrier, date_upd, date_add) VALUES (?, ?, ?, ?)' with params [13, "postnl", "2024-06-09 16:51:33", "2024-06-09 16:51:33"]:\n\nSQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'postnl' for key 'myparcel_carrier'

So I am not having much luck with this plugin.

Also I downloaded and installed the myparcelnl-prestashop-4.0.0-beta.3.zip however after installing it, it will present itself as 'MyParcelNL v4.0.0-be - by MyParcel'.

Also the webhooks are not created, they all have a red crosses in front of the them, however when I click on the 'create webhook' button I get the following exception, and they still have red crosses.

message | "Request failed. Status code: 400. Errors: Webhook validation error (request_id: 1717944930.66476665c262a2493)"

EdieLemoine commented 2 months ago

Hi @mariuszsienkiewicz, now that I think of it and realize this is also about PostNL, this is most likely the same problem as myparcelnl/pdk#284. I will close as duplicate, but feel free to reopen if this turns out to happen with other carriers as well.