diff --git a/psgdpr.php b/psgdpr.php index ecd47512..537d665c 100755 --- a/psgdpr.php +++ b/psgdpr.php @@ -59,6 +59,7 @@ class Psgdpr extends Module 'actionAdminControllerSetMedia', 'additionalCustomerFormFields', 'actionCustomerAccountAdd', + 'actionModuleRegisterHookAfter', ]; private $presetMessageAccountCreation = [ @@ -87,7 +88,7 @@ public function __construct() { $this->name = 'psgdpr'; $this->tab = 'administration'; - $this->version = '2.0.3'; + $this->version = '2.0.4'; $this->author = 'PrestaShop'; $this->need_instance = 0; @@ -153,6 +154,7 @@ public function install(): bool $this->registerHook($this->hooksUsedByModule); $this->executeQuerySql(self::SQL_QUERY_TYPE_UNINSTALL); $this->executeQuerySql(self::SQL_QUERY_TYPE_INSTALL); + $this->getRegisteredModules(); } catch (PrestaShopException $e) { /** @var LegacyLogger $legacyLogger */ $legacyLogger = $this->get('prestashop.adapter.legacy.logger'); @@ -267,7 +269,6 @@ public function getContent() $id_lang = $this->context->language->id; $id_shop = $this->context->shop->id; - $this->getRegisteredModules(); $moduleList = $this->loadRegisteredModules(); $apiController = $router->generate('psgdpr_api_index'); @@ -781,6 +782,34 @@ public function hookDisplayGDPRConsent(array $params): string return $this->fetch('module:' . $this->name . '/views/templates/hook/display_rgpd_consent.tpl'); } + public function hookActionModuleRegisterHookAfter(array $params): void + { + $hookName = $params['hookName'] ?? null; + $moduleObject = $params['object'] ?? null; + + if ($hookName != 'registerGDPRConsent' || !is_a($moduleObject, Module::class)) { + return; + } + + try { + $this->addModuleConsent([ + 'id_module' => $moduleObject->id, + ]); + } catch (PrestaShopException $e) { + /** @var LegacyLogger $legacyLogger */ + $legacyLogger = $this->get('prestashop.adapter.legacy.logger'); + $legacyLogger->error($e->getMessage(), [ + 'file' => $e->getFile(), + 'line' => $e->getLine(), + ]); + $this->_errors[] = $this->trans( + 'There was an error during to add the module %module_name% consent. Please contact us through Addons website. (for developers, consult shop logs)', + ['%module_name%' => $moduleObject->name], + 'Modules.Psgdpr.Shop' + ); + } + } + /** * Execute raw sql query from specific folder * Used mainly for the install or uninstall of the psgdpr module diff --git a/upgrade/upgrade-2.0.4.php b/upgrade/upgrade-2.0.4.php new file mode 100644 index 00000000..981ef287 --- /dev/null +++ b/upgrade/upgrade-2.0.4.php @@ -0,0 +1,33 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) + */ +if (!defined('_PS_VERSION_')) { + exit; +} + +/** + * @param Psgdpr $module + * + * @return bool + */ +function upgrade_module_2_0_4($module) +{ + return $module->registerHook('actionModuleRegisterHookAfter'); +}