From 8a973c67c5b3518e6d66fedad6f7a9c0aa328d4a Mon Sep 17 00:00:00 2001 From: Prestaplugins Date: Fri, 4 Sep 2026 11:53:08 +0200 Subject: [PATCH 1/4] Add missing indexes on emailsubscription table --- config.xml | 2 +- ps_emailsubscription.php | 6 ++-- upgrade/upgrade-3.0.1.php | 67 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 upgrade/upgrade-3.0.1.php diff --git a/config.xml b/config.xml index dca4051..4768e3c 100644 --- a/config.xml +++ b/config.xml @@ -2,7 +2,7 @@ ps_emailsubscription - + diff --git a/ps_emailsubscription.php b/ps_emailsubscription.php index 375734e..3cb6355 100644 --- a/ps_emailsubscription.php +++ b/ps_emailsubscription.php @@ -100,7 +100,7 @@ public function __construct() $this->confirmUninstall = $this->trans('Are you sure that you want to delete all of your contacts?', [], 'Modules.Emailsubscription.Admin'); $this->ps_versions_compliancy = ['min' => '8.2.0', 'max' => _PS_VERSION_]; - $this->version = '3.0.0'; + $this->version = '3.0.1'; $this->author = 'PrestaShop'; $this->error = false; $this->valid = false; @@ -168,7 +168,9 @@ public function install() `http_referer` VARCHAR(255) NULL, `active` TINYINT(1) NOT NULL DEFAULT \'0\', `id_lang` int(10) NOT NULL DEFAULT \'0\', - PRIMARY KEY(`id`) + PRIMARY KEY(`id`), + KEY `email` (`email`), + KEY `id_shop_lang` (`id_shop`, `id_lang`) ) ENGINE=' . _MYSQL_ENGINE_ . ' default CHARSET=utf8'); } diff --git a/upgrade/upgrade-3.0.1.php b/upgrade/upgrade-3.0.1.php new file mode 100644 index 0000000..e67e7a8 --- /dev/null +++ b/upgrade/upgrade-3.0.1.php @@ -0,0 +1,67 @@ + + * @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 Module $module + * + * @return bool + */ +function upgrade_module_3_0_1($module) +{ + $result = true; + + if (!ps_emailsubscription_index_exists('emailsubscription', 'email')) { + $result = $result && Db::getInstance()->execute( + 'ALTER TABLE `' . _DB_PREFIX_ . 'emailsubscription` ADD KEY `email` (`email`)' + ); + } + + if (!ps_emailsubscription_index_exists('emailsubscription', 'id_shop_lang')) { + $result = $result && Db::getInstance()->execute( + 'ALTER TABLE `' . _DB_PREFIX_ . 'emailsubscription` ADD KEY `id_shop_lang` (`id_shop`, `id_lang`)' + ); + } + + return $result; +} + +/** + * @param string $table Table name without prefix + * @param string $indexName + * + * @return bool + */ +function ps_emailsubscription_index_exists($table, $indexName) +{ + $row = Db::getInstance()->getRow( + 'SHOW INDEX FROM `' . _DB_PREFIX_ . bqSQL($table) . '` WHERE Key_name = \'' . pSQL($indexName) . '\'' + ); + + return !empty($row); +} From cc4dd4cbb4626f686010edbc46e564f7fe68009a Mon Sep 17 00:00:00 2001 From: Prestaplugins Date: Fri, 4 Sep 2026 11:53:08 +0200 Subject: [PATCH 2/4] Simplify upgrade script: always add indexes --- upgrade/upgrade-3.0.1.php | 33 ++++----------------------------- 1 file changed, 4 insertions(+), 29 deletions(-) diff --git a/upgrade/upgrade-3.0.1.php b/upgrade/upgrade-3.0.1.php index e67e7a8..3f3367d 100644 --- a/upgrade/upgrade-3.0.1.php +++ b/upgrade/upgrade-3.0.1.php @@ -34,34 +34,9 @@ */ function upgrade_module_3_0_1($module) { - $result = true; - - if (!ps_emailsubscription_index_exists('emailsubscription', 'email')) { - $result = $result && Db::getInstance()->execute( - 'ALTER TABLE `' . _DB_PREFIX_ . 'emailsubscription` ADD KEY `email` (`email`)' - ); - } - - if (!ps_emailsubscription_index_exists('emailsubscription', 'id_shop_lang')) { - $result = $result && Db::getInstance()->execute( - 'ALTER TABLE `' . _DB_PREFIX_ . 'emailsubscription` ADD KEY `id_shop_lang` (`id_shop`, `id_lang`)' - ); - } - - return $result; -} - -/** - * @param string $table Table name without prefix - * @param string $indexName - * - * @return bool - */ -function ps_emailsubscription_index_exists($table, $indexName) -{ - $row = Db::getInstance()->getRow( - 'SHOW INDEX FROM `' . _DB_PREFIX_ . bqSQL($table) . '` WHERE Key_name = \'' . pSQL($indexName) . '\'' + return Db::getInstance()->execute( + 'ALTER TABLE `' . _DB_PREFIX_ . 'emailsubscription` + ADD KEY `email` (`email`), + ADD KEY `id_shop_lang` (`id_shop`, `id_lang`)' ); - - return !empty($row); } From e34af7d331173fe759a4b8b37e84ac768092ef13 Mon Sep 17 00:00:00 2001 From: Prestaplugins Date: Fri, 4 Sep 2026 11:53:08 +0200 Subject: [PATCH 3/4] Do not bump module version; keep upgrade script for next release --- config.xml | 2 +- ps_emailsubscription.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config.xml b/config.xml index 4768e3c..dca4051 100644 --- a/config.xml +++ b/config.xml @@ -2,7 +2,7 @@ ps_emailsubscription - + diff --git a/ps_emailsubscription.php b/ps_emailsubscription.php index 3cb6355..1699551 100644 --- a/ps_emailsubscription.php +++ b/ps_emailsubscription.php @@ -100,7 +100,7 @@ public function __construct() $this->confirmUninstall = $this->trans('Are you sure that you want to delete all of your contacts?', [], 'Modules.Emailsubscription.Admin'); $this->ps_versions_compliancy = ['min' => '8.2.0', 'max' => _PS_VERSION_]; - $this->version = '3.0.1'; + $this->version = '3.0.0'; $this->author = 'PrestaShop'; $this->error = false; $this->valid = false; From 9aaffd0a039023945e180f78adedcecd0477e63a Mon Sep 17 00:00:00 2001 From: Prestaplugins Date: Fri, 4 Sep 2026 14:53:16 +0200 Subject: [PATCH 4/4] Align indexes with real query filters: (email, id_shop) and (active, id_shop) --- ps_emailsubscription.php | 4 ++-- upgrade/upgrade-3.0.1.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ps_emailsubscription.php b/ps_emailsubscription.php index 1699551..26cb08b 100644 --- a/ps_emailsubscription.php +++ b/ps_emailsubscription.php @@ -169,8 +169,8 @@ public function install() `active` TINYINT(1) NOT NULL DEFAULT \'0\', `id_lang` int(10) NOT NULL DEFAULT \'0\', PRIMARY KEY(`id`), - KEY `email` (`email`), - KEY `id_shop_lang` (`id_shop`, `id_lang`) + KEY `email_shop` (`email`, `id_shop`), + KEY `active_shop` (`active`, `id_shop`) ) ENGINE=' . _MYSQL_ENGINE_ . ' default CHARSET=utf8'); } diff --git a/upgrade/upgrade-3.0.1.php b/upgrade/upgrade-3.0.1.php index 3f3367d..401d650 100644 --- a/upgrade/upgrade-3.0.1.php +++ b/upgrade/upgrade-3.0.1.php @@ -36,7 +36,7 @@ function upgrade_module_3_0_1($module) { return Db::getInstance()->execute( 'ALTER TABLE `' . _DB_PREFIX_ . 'emailsubscription` - ADD KEY `email` (`email`), - ADD KEY `id_shop_lang` (`id_shop`, `id_lang`)' + ADD KEY `email_shop` (`email`, `id_shop`), + ADD KEY `active_shop` (`active`, `id_shop`)' ); }