diff --git a/install.sql b/install.sql deleted file mode 100644 index bb775562..00000000 --- a/install.sql +++ /dev/null @@ -1,75 +0,0 @@ -CREATE TABLE IF NOT EXISTS `PREFIX_product_comment` ( - `id_product_comment` int(10) unsigned NOT NULL auto_increment, - `id_product` int(10) unsigned NOT NULL, - `id_customer` int(10) unsigned NOT NULL, - `id_guest` int(10) unsigned NULL, - `title` varchar(64) NULL, - `content` text NOT NULL, - `customer_name` varchar(64) NULL, - `grade` float unsigned NOT NULL, - `validate` tinyint(1) NOT NULL, - `deleted` tinyint(1) NOT NULL, - `date_add` datetime NOT NULL, - PRIMARY KEY (`id_product_comment`), - KEY `id_product` (`id_product`), - KEY `id_customer` (`id_customer`), - KEY `id_guest` (`id_guest`) -) 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=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=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=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=utf8mb4; - -CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_grade` ( - `id_product_comment` int(10) unsigned NOT NULL, - `id_product_comment_criterion` int(10) unsigned NOT NULL, - `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; - -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=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=utf8mb4; - -INSERT IGNORE INTO `PREFIX_product_comment_criterion` VALUES ('1', '1', '1'); - -INSERT IGNORE INTO `PREFIX_product_comment_criterion_lang` (`id_product_comment_criterion`, `id_lang`, `name`) - ( - SELECT '1', l.`id_lang`, 'Quality' - FROM `PREFIX_lang` l - ); - diff --git a/productcomments.php b/productcomments.php index 6d22ab0c..46eafcd6 100644 --- a/productcomments.php +++ b/productcomments.php @@ -33,8 +33,6 @@ class ProductComments extends Module implements WidgetInterface { - const INSTALL_SQL_FILE = 'install.sql'; - private $_html = ''; private $_productCommentsCriterionTypes = []; @@ -47,7 +45,7 @@ public function __construct() { $this->name = 'productcomments'; $this->tab = 'front_office_features'; - $this->version = '6.0.3'; + $this->version = '6.0.4'; $this->author = 'PrestaShop'; $this->need_instance = 0; $this->bootstrap = true; @@ -70,19 +68,8 @@ public function install($keep = true) } if ($keep) { - if (!file_exists(dirname(__FILE__) . '/' . self::INSTALL_SQL_FILE)) { - return false; - } elseif (!$sql = file_get_contents(dirname(__FILE__) . '/' . self::INSTALL_SQL_FILE)) { - return false; - } - $sql = str_replace(['PREFIX_', 'ENGINE_TYPE'], [_DB_PREFIX_, _MYSQL_ENGINE_], $sql); - $sql = preg_split("/;\s*[\r\n]+/", trim($sql)); - - foreach ($sql as $query) { - if (!Db::getInstance()->execute(trim($query))) { - return false; - } - } + $entitySchemaManager = $this->getEntitySchemaManager(); + $entitySchemaManager->createMultiple($this->getEntitiesList()); } if ( @@ -149,16 +136,21 @@ public function reset() public function deleteTables() { - return Db::getInstance()->execute(' - DROP TABLE IF EXISTS - `' . _DB_PREFIX_ . 'product_comment`, - `' . _DB_PREFIX_ . 'product_comment_criterion`, - `' . _DB_PREFIX_ . 'product_comment_criterion_product`, - `' . _DB_PREFIX_ . 'product_comment_criterion_lang`, - `' . _DB_PREFIX_ . 'product_comment_criterion_category`, - `' . _DB_PREFIX_ . 'product_comment_grade`, - `' . _DB_PREFIX_ . 'product_comment_usefulness`, - `' . _DB_PREFIX_ . 'product_comment_report`'); + $entitySchemaManager = $this->getEntitySchemaManager(); + + return $entitySchemaManager->dropMultiple($this->getEntitiesList()); + } + + /** + * Update entities tables schema + * + * @return bool + */ + public function updateTablesSchema(): bool + { + $entitySchemaManager = $this->getEntitySchemaManager(); + + return $entitySchemaManager->updateMultiple($this->getEntitiesList()); } public function getCacheId($id_product = null) @@ -1104,4 +1096,21 @@ public function hookRegisterGDPRConsent() at module installation. */ } + + /** + * Return array with module Symfony entities list + * + * @return array + */ + protected function getEntitiesList(): array + { + return [ + PrestaShop\Module\ProductComment\Entity\ProductComment::class, + PrestaShop\Module\ProductComment\Entity\ProductCommentCriterion::class, + PrestaShop\Module\ProductComment\Entity\ProductCommentCriterionLang::class, + PrestaShop\Module\ProductComment\Entity\ProductCommentGrade::class, + PrestaShop\Module\ProductComment\Entity\ProductCommentReport::class, + PrestaShop\Module\ProductComment\Entity\ProductCommentUsefulness::class, + ]; + } } diff --git a/upgrade/install-6.0.4.php b/upgrade/install-6.0.4.php new file mode 100644 index 00000000..2ad73574 --- /dev/null +++ b/upgrade/install-6.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; +} + +function upgrade_module_6_0_4($module) +{ + return $module->updateTablesSchema(); +}