From 76b15dd9fa881c738cca8f2af781f5e2e076031b Mon Sep 17 00:00:00 2001 From: leemyongpakvn Date: Tue, 21 Jun 2022 09:43:06 +0700 Subject: [PATCH 01/12] Remove unused ProductCriterion.php ProductCriterion.php is not used anywhere. --- tests/phpstan/phpstan.neon | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/phpstan/phpstan.neon b/tests/phpstan/phpstan.neon index 3c61edce..d932a938 100644 --- a/tests/phpstan/phpstan.neon +++ b/tests/phpstan/phpstan.neon @@ -5,8 +5,7 @@ parameters: # From PHPStan 0.12, paths to check are relative to the neon file - ../../productcomments.php - ../../ProductComment.php - - ../../ProductCommentCriterion.php - - ../../ProductCriterion.php + - ../../ProductCommentCriterion.php - ../../controllers/ - ../../src/ - ../../upgrade/ From 53f458923207104e0139e0a6d261e85aa9c0e8ef Mon Sep 17 00:00:00 2001 From: leemyongpakvn Date: Tue, 21 Jun 2022 09:56:43 +0700 Subject: [PATCH 02/12] Delete ProductCriterion.php --- ProductCriterion.php | 192 ------------------------------------------- 1 file changed, 192 deletions(-) delete mode 100644 ProductCriterion.php diff --git a/ProductCriterion.php b/ProductCriterion.php deleted file mode 100644 index f9ce4f69..00000000 --- a/ProductCriterion.php +++ /dev/null @@ -1,192 +0,0 @@ - - * @copyright Since 2007 PrestaShop SA and Contributors - * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) - */ -class ProductCommentCriterion -{ - /** - * Add a Comment Criterion - * - * @return bool succeed - */ - public static function add($id_lang, $name) - { - if (!Validate::isUnsignedId($id_lang) || - !Validate::isMessage($name)) { - exit(Tools::displayError()); - } - - return Db::getInstance()->execute(' - INSERT INTO `' . _DB_PREFIX_ . 'product_comment_criterion` - (`id_lang`, `name`) VALUES( - ' . (int) ($id_lang) . ', - \'' . pSQL($name) . '\')'); - } - - /** - * Link a Comment Criterion to a product - * - * @return bool succeed - */ - public static function addToProduct($id_product_comment_criterion, $id_product) - { - if (!Validate::isUnsignedId($id_product_comment_criterion) || - !Validate::isUnsignedId($id_product)) { - exit(Tools::displayError()); - } - - return Db::getInstance()->execute(' - INSERT INTO `' . _DB_PREFIX_ . 'product_comment_criterion_product` - (`id_product_comment_criterion`, `id_product`) VALUES( - ' . (int) ($id_product_comment_criterion) . ', - ' . (int) ($id_product) . ')'); - } - - /** - * Add grade to a criterion - * - * @return bool succeed - */ - public static function addGrade($id_product_comment, $id_product_comment_criterion, $grade) - { - if (!Validate::isUnsignedId($id_product_comment) || - !Validate::isUnsignedId($id_product_comment_criterion)) { - exit(Tools::displayError()); - } - if ($grade < 0) { - $grade = 0; - } elseif ($grade > 10) { - $grade = 10; - } - - return Db::getInstance()->execute(' - INSERT INTO `' . _DB_PREFIX_ . 'product_comment_grade` - (`id_product_comment`, `id_product_comment_criterion`, `grade`) VALUES( - ' . (int) ($id_product_comment) . ', - ' . (int) ($id_product_comment_criterion) . ', - ' . (int) ($grade) . ')'); - } - - /** - * Update criterion - * - * @return bool succeed - */ - public static function update($id_product_comment_criterion, $id_lang, $name) - { - if (!Validate::isUnsignedId($id_product_comment_criterion) || - !Validate::isUnsignedId($id_lang) || - !Validate::isMessage($name)) { - exit(Tools::displayError()); - } - - return Db::getInstance()->execute(' - UPDATE `' . _DB_PREFIX_ . 'product_comment_criterion` SET - `name` = \'' . pSQL($name) . '\' - WHERE `id_product_comment_criterion` = ' . (int) ($id_product_comment_criterion) . ' AND - `id_lang` = ' . (int) ($id_lang)); - } - - /** - * Get criterion by Product - * - * @return array Criterion - */ - public static function getByProduct($id_product, $id_lang) - { - if (!Validate::isUnsignedId($id_product) || - !Validate::isUnsignedId($id_lang)) { - exit(Tools::displayError()); - } - - return Db::getInstance()->executeS(' - SELECT pcc.`id_product_comment_criterion`, pcc.`name` - FROM `' . _DB_PREFIX_ . 'product_comment_criterion` pcc - INNER JOIN `' . _DB_PREFIX_ . 'product_comment_criterion_product` pccp ON pcc.`id_product_comment_criterion` = pccp.`id_product_comment_criterion` - WHERE pccp.`id_product` = ' . (int) ($id_product) . ' AND - pcc.`id_lang` = ' . (int) ($id_lang)); - } - - /** - * Get Criterions - * - * @return array Criterions - */ - public static function get($id_lang) - { - if (!Validate::isUnsignedId($id_lang)) { - exit(Tools::displayError()); - } - - return Db::getInstance()->executeS(' - SELECT pcc.`id_product_comment_criterion`, pcc.`name` - FROM `' . _DB_PREFIX_ . 'product_comment_criterion` pcc - WHERE pcc.`id_lang` = ' . (int) ($id_lang) . ' - ORDER BY pcc.`name` ASC'); - } - - /** - * Delete product criterion by product - * - * @return bool succeed - */ - public static function deleteByProduct($id_product) - { - if (!Validate::isUnsignedId($id_product)) { - exit(Tools::displayError()); - } - - return Db::getInstance()->execute(' - DELETE FROM `' . _DB_PREFIX_ . 'product_comment_criterion_product` - WHERE `id_product` = ' . (int) ($id_product)); - } - - /** - * Delete all reference of a criterion - * - * @return bool succeed - */ - public static function delete($id_product_comment_criterion) - { - if (!Validate::isUnsignedId($id_product_comment_criterion)) { - exit(Tools::displayError()); - } - $result = Db::getInstance()->execute(' - DELETE FROM `' . _DB_PREFIX_ . 'product_comment_grade` - WHERE `id_product_comment_criterion` = ' . (int) ($id_product_comment_criterion)); - if ($result === false) { - return $result; - } - $result = Db::getInstance()->execute(' - DELETE FROM `' . _DB_PREFIX_ . 'product_comment_criterion_product` - WHERE `id_product_comment_criterion` = ' . (int) ($id_product_comment_criterion)); - if ($result === false) { - return $result; - } - - return Db::getInstance()->execute(' - DELETE FROM `' . _DB_PREFIX_ . 'product_comment_criterion` - WHERE `id_product_comment_criterion` = ' . (int) ($id_product_comment_criterion)); - } -} From 6577f2c122088fe5039b8cdd65d7f967b1429120 Mon Sep 17 00:00:00 2001 From: leemyongpakvn Date: Fri, 24 Jun 2022 22:08:27 +0700 Subject: [PATCH 03/12] Replace deprecated CHARSET utf8 in install.sql deprecated CHARSET utf8 need to be replaced by utf8mb4 --- install.sql | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/install.sql b/install.sql index 53ee6cb6..bb775562 100644 --- a/install.sql +++ b/install.sql @@ -14,35 +14,35 @@ CREATE TABLE IF NOT EXISTS `PREFIX_product_comment` ( KEY `id_product` (`id_product`), KEY `id_customer` (`id_customer`), KEY `id_guest` (`id_guest`) -) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; +) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4; CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_criterion` ( `id_product_comment_criterion` int(10) unsigned NOT NULL auto_increment, `id_product_comment_criterion_type` tinyint(1) NOT NULL, `active` tinyint(1) NOT NULL, PRIMARY KEY (`id_product_comment_criterion`) -) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; +) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4; CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_criterion_product` ( `id_product` int(10) unsigned NOT NULL, `id_product_comment_criterion` int(10) unsigned NOT NULL, PRIMARY KEY(`id_product`, `id_product_comment_criterion`), KEY `id_product_comment_criterion` (`id_product_comment_criterion`) -) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; +) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4; CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_criterion_lang` ( `id_product_comment_criterion` INT(11) UNSIGNED NOT NULL , `id_lang` INT(11) UNSIGNED NOT NULL , `name` VARCHAR(64) NOT NULL , PRIMARY KEY ( `id_product_comment_criterion` , `id_lang` ) -) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; +) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4; CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_criterion_category` ( `id_product_comment_criterion` int(10) unsigned NOT NULL, `id_category` int(10) unsigned NOT NULL, PRIMARY KEY(`id_product_comment_criterion`, `id_category`), KEY `id_category` (`id_category`) -) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; +) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4; CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_grade` ( `id_product_comment` int(10) unsigned NOT NULL, @@ -50,20 +50,20 @@ CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_grade` ( `grade` int(10) unsigned NOT NULL, PRIMARY KEY (`id_product_comment`, `id_product_comment_criterion`), KEY `id_product_comment_criterion` (`id_product_comment_criterion`) -) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; +) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4; CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_usefulness` ( `id_product_comment` int(10) unsigned NOT NULL, `id_customer` int(10) unsigned NOT NULL, `usefulness` tinyint(1) unsigned NOT NULL, PRIMARY KEY (`id_product_comment`, `id_customer`) -) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; +) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4; CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_report` ( `id_product_comment` int(10) unsigned NOT NULL, `id_customer` int(10) unsigned NOT NULL, PRIMARY KEY (`id_product_comment`, `id_customer`) -) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; +) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4; INSERT IGNORE INTO `PREFIX_product_comment_criterion` VALUES ('1', '1', '1'); From b763630e063d3b8f2e62b6cd8d9ce1d2efb11d53 Mon Sep 17 00:00:00 2001 From: leemyongpakvn Date: Sun, 26 Jun 2022 07:36:28 +0700 Subject: [PATCH 04/12] Update install.sql Co-authored-by: Krystian Podemski --- install.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sql b/install.sql index bb775562..e3119f90 100644 --- a/install.sql +++ b/install.sql @@ -14,7 +14,7 @@ CREATE TABLE IF NOT EXISTS `PREFIX_product_comment` ( KEY `id_product` (`id_product`), KEY `id_customer` (`id_customer`), KEY `id_guest` (`id_guest`) -) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4; +) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_criterion` ( `id_product_comment_criterion` int(10) unsigned NOT NULL auto_increment, From be055594c00a4c348e416b8dcb68e4406881dc94 Mon Sep 17 00:00:00 2001 From: leemyongpakvn Date: Sun, 26 Jun 2022 07:36:35 +0700 Subject: [PATCH 05/12] Update install.sql Co-authored-by: Krystian Podemski --- install.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sql b/install.sql index e3119f90..5371a441 100644 --- a/install.sql +++ b/install.sql @@ -28,7 +28,7 @@ CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_criterion_product` ( `id_product_comment_criterion` int(10) unsigned NOT NULL, PRIMARY KEY(`id_product`, `id_product_comment_criterion`), KEY `id_product_comment_criterion` (`id_product_comment_criterion`) -) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4; +) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_criterion_lang` ( `id_product_comment_criterion` INT(11) UNSIGNED NOT NULL , From 0a3c4474c9bf4ad73362166c852cec4a3f065085 Mon Sep 17 00:00:00 2001 From: leemyongpakvn Date: Sun, 26 Jun 2022 07:36:55 +0700 Subject: [PATCH 06/12] Update install.sql Co-authored-by: Krystian Podemski --- install.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sql b/install.sql index 5371a441..43bfc1b7 100644 --- a/install.sql +++ b/install.sql @@ -42,7 +42,7 @@ CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_criterion_category` ( `id_category` int(10) unsigned NOT NULL, PRIMARY KEY(`id_product_comment_criterion`, `id_category`), KEY `id_category` (`id_category`) -) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4; +) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_grade` ( `id_product_comment` int(10) unsigned NOT NULL, From 09df320203cee6e3a01a4be5d1c6f1013338607d Mon Sep 17 00:00:00 2001 From: leemyongpakvn Date: Sun, 26 Jun 2022 07:37:21 +0700 Subject: [PATCH 07/12] Update install.sql Co-authored-by: Krystian Podemski --- install.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sql b/install.sql index 43bfc1b7..4017fe5f 100644 --- a/install.sql +++ b/install.sql @@ -21,7 +21,7 @@ CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_criterion` ( `id_product_comment_criterion_type` tinyint(1) NOT NULL, `active` tinyint(1) NOT NULL, PRIMARY KEY (`id_product_comment_criterion`) -) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4; +) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_criterion_product` ( `id_product` int(10) unsigned NOT NULL, From 5ef856a25b47787b3918091cca09d3a806eb195a Mon Sep 17 00:00:00 2001 From: leemyongpakvn Date: Sun, 26 Jun 2022 07:39:55 +0700 Subject: [PATCH 08/12] Update install.sql Co-authored-by: Krystian Podemski --- install.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sql b/install.sql index 4017fe5f..981cd0d9 100644 --- a/install.sql +++ b/install.sql @@ -50,7 +50,7 @@ CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_grade` ( `grade` int(10) unsigned NOT NULL, PRIMARY KEY (`id_product_comment`, `id_product_comment_criterion`), KEY `id_product_comment_criterion` (`id_product_comment_criterion`) -) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4; +) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_usefulness` ( `id_product_comment` int(10) unsigned NOT NULL, From a23f7addd80501a8f83f298d89f0c90982c7e926 Mon Sep 17 00:00:00 2001 From: leemyongpakvn Date: Sun, 26 Jun 2022 07:40:03 +0700 Subject: [PATCH 09/12] Update install.sql Co-authored-by: Krystian Podemski --- install.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sql b/install.sql index 981cd0d9..ae26cd74 100644 --- a/install.sql +++ b/install.sql @@ -57,7 +57,7 @@ CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_usefulness` ( `id_customer` int(10) unsigned NOT NULL, `usefulness` tinyint(1) unsigned NOT NULL, PRIMARY KEY (`id_product_comment`, `id_customer`) -) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4; +) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_report` ( `id_product_comment` int(10) unsigned NOT NULL, From 907df5cdd7cf91124939078ce42dd7215bd9aca0 Mon Sep 17 00:00:00 2001 From: leemyongpakvn Date: Sun, 26 Jun 2022 07:40:09 +0700 Subject: [PATCH 10/12] Update install.sql Co-authored-by: Krystian Podemski --- install.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sql b/install.sql index ae26cd74..a55bbec3 100644 --- a/install.sql +++ b/install.sql @@ -63,7 +63,7 @@ CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_report` ( `id_product_comment` int(10) unsigned NOT NULL, `id_customer` int(10) unsigned NOT NULL, PRIMARY KEY (`id_product_comment`, `id_customer`) -) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4; +) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; INSERT IGNORE INTO `PREFIX_product_comment_criterion` VALUES ('1', '1', '1'); From 1459919bf1cb9642ff13cfc001cda80ab640336a Mon Sep 17 00:00:00 2001 From: leemyongpakvn Date: Sun, 26 Jun 2022 14:28:44 +0700 Subject: [PATCH 11/12] Update tests/phpstan/phpstan.neon Co-authored-by: Thomas Roux --- tests/phpstan/phpstan.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpstan/phpstan.neon b/tests/phpstan/phpstan.neon index d932a938..037652f7 100644 --- a/tests/phpstan/phpstan.neon +++ b/tests/phpstan/phpstan.neon @@ -5,7 +5,7 @@ parameters: # From PHPStan 0.12, paths to check are relative to the neon file - ../../productcomments.php - ../../ProductComment.php - - ../../ProductCommentCriterion.php + - ../../ProductCommentCriterion.php - ../../controllers/ - ../../src/ - ../../upgrade/ From 329cd75ce275c6a7097a17fc17aeb08f0cf85f0d Mon Sep 17 00:00:00 2001 From: leemyongpakvn Date: Sun, 26 Jun 2022 14:28:54 +0700 Subject: [PATCH 12/12] Update install.sql Co-authored-by: Thomas Roux --- install.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sql b/install.sql index a55bbec3..53ee6cb6 100644 --- a/install.sql +++ b/install.sql @@ -35,7 +35,7 @@ CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_criterion_lang` ( `id_lang` INT(11) UNSIGNED NOT NULL , `name` VARCHAR(64) NOT NULL , PRIMARY KEY ( `id_product_comment_criterion` , `id_lang` ) -) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4; +) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_criterion_category` ( `id_product_comment_criterion` int(10) unsigned NOT NULL,