From 6e0526edc5defffaedf03e56f1cb7719cd9cb37c Mon Sep 17 00:00:00 2001 From: dMetzger Date: Fri, 7 Sep 2012 08:32:07 +0000 Subject: [PATCH] // Added 1.4.9 update files --- .../upgrade/php/clean_category_product.php | 44 +++++++++++ install-dev/upgrade/php/moduleReinstaller.php | 37 +++++++++ .../php/update_module_blocklayered.php | 34 ++++++++ .../upgrade/php/update_module_mailalerts.php | 77 +++++++++++++++++++ .../php/update_module_pagesnotfound.php | 42 ++++++++++ install-dev/upgrade/sql/1.4.9.0.sql | 27 +++++++ install-dev/upgrade/sql/1.4.9.1.sql | 3 + 7 files changed, 264 insertions(+) create mode 100644 install-dev/upgrade/php/clean_category_product.php create mode 100644 install-dev/upgrade/php/moduleReinstaller.php create mode 100644 install-dev/upgrade/php/update_module_blocklayered.php create mode 100644 install-dev/upgrade/php/update_module_mailalerts.php create mode 100644 install-dev/upgrade/php/update_module_pagesnotfound.php create mode 100644 install-dev/upgrade/sql/1.4.9.0.sql create mode 100644 install-dev/upgrade/sql/1.4.9.1.sql diff --git a/install-dev/upgrade/php/clean_category_product.php b/install-dev/upgrade/php/clean_category_product.php new file mode 100644 index 000000000..eec4a2173 --- /dev/null +++ b/install-dev/upgrade/php/clean_category_product.php @@ -0,0 +1,44 @@ + +* @copyright 2007-2012 PrestaShop SA +* @version Release: $Revision: 14012 $ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +/* Remove duplicate entries from ps_category_product */ +function clean_category_product() +{ + $list = Db::getInstance()->ExecuteS(' + SELECT id_category, id_product, COUNT(*) n + FROM '._DB_PREFIX_.'category_product + GROUP BY CONCAT(id_category,\'|\',id_product) + HAVING n > 1'); + + $result = true; + if ($list) + foreach ($list as $l) + $result &= Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'category_product + WHERE id_product = '.(int)$l['id_product'].' AND id_category = '.(int)$l['id_category'].' LIMIT '.(int)($l['n'] - 1)); + + return $result; +} \ No newline at end of file diff --git a/install-dev/upgrade/php/moduleReinstaller.php b/install-dev/upgrade/php/moduleReinstaller.php new file mode 100644 index 000000000..0906a09c1 --- /dev/null +++ b/install-dev/upgrade/php/moduleReinstaller.php @@ -0,0 +1,37 @@ + +* @copyright 2007-2012 PrestaShop SA +* @version Release: $Revision: 14012 $ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +function moduleReinstaller($moduleName, $force = false) +{ + $module = Module::getInstanceByName($moduleName); + if (!is_object($module)) + die(Tools::displayError()); + if ($module->uninstall() OR $force) + return $module->install(); + return false; +} + diff --git a/install-dev/upgrade/php/update_module_blocklayered.php b/install-dev/upgrade/php/update_module_blocklayered.php new file mode 100644 index 000000000..d5158fc4b --- /dev/null +++ b/install-dev/upgrade/php/update_module_blocklayered.php @@ -0,0 +1,34 @@ + +* @copyright 2007-2012 PrestaShop SA +* @version Release: $Revision: 14012 $ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +function update_module_blocklayered() +{ + if (Db::getInstance()->getValue('SELECT id_module FROM `'._DB_PREFIX_.'module` WHERE name = \'blocklayered\'')) + @Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_.'layered_price_index` ADD INDEX id_product (`id_product`)'); + + return true; +} \ No newline at end of file diff --git a/install-dev/upgrade/php/update_module_mailalerts.php b/install-dev/upgrade/php/update_module_mailalerts.php new file mode 100644 index 000000000..cb831f7be --- /dev/null +++ b/install-dev/upgrade/php/update_module_mailalerts.php @@ -0,0 +1,77 @@ + +* @copyright 2007-2012 PrestaShop SA +* @version Release: $Revision: 14012 $ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +function update_module_mailalerts() +{ + if (Db::getInstance()->getValue('SELECT id_module FROM `'._DB_PREFIX_.'module` WHERE name = \'mailalerts\'')) + { + $result = Db::getInstance()->Execute(' + CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'mailalert_customer_oos_new` ( + `id_customer` int(10) unsigned NOT NULL, + `customer_email` varchar(128) NOT NULL, + `id_product` int(10) unsigned NOT NULL, + `id_product_attribute` int(10) unsigned NOT NULL, + `id_lang` int(10) unsigned NOT NULL, + `date_add` datetime NOT NULL, + PRIMARY KEY (`id_customer`, `customer_email`, `id_product`, `id_product_attribute`, `id_lang`), + KEY `customer_email` (`customer_email`), + KEY `id_product` (`id_product`,`id_product_attribute`) + ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;'); + + $default_language = (int)Configuration::get('PS_LANG_DEFAULT'); + $current_time = date('Y-m-d H:i:s'); + $existing_alerts = Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'mailalert_customer_oos`', false); + $result &= (bool)$existing_alerts; + + if ($result) + { + $total_alerts = (int)Db::getInstance()->NumRows(); + while ($row = Db::getInstance()->nextRow($existing_alerts)) + { + if (!isset($row['id_lang'])) + $row['id_lang'] = $default_language; + if (!isset($row['date_add'])) + $row['date_add'] = $current_time; + + $result &= Db::getInstance()->AutoExecute(_DB_PREFIX_.'mailalert_customer_oos_new', $row, 'INSERT'); + } + + $total_new_alerts = (int)Db::getInstance()->getValue('SELECT COUNT(*) FROM `'._DB_PREFIX_.'mailalert_customer_oos_new`'); + + if ($result && $total_alerts == $total_new_alerts) + { + $result &= Db::getInstance()->Execute('DROP TABLE '._DB_PREFIX_.'mailalert_customer_oos'); + if ($result) + $result &= Db::getInstance()->Execute('RENAME TABLE '._DB_PREFIX_.'mailalert_customer_oos_new TO '._DB_PREFIX_.'mailalert_customer_oos'); + } + } + + return $result; + } + + return true; +} \ No newline at end of file diff --git a/install-dev/upgrade/php/update_module_pagesnotfound.php b/install-dev/upgrade/php/update_module_pagesnotfound.php new file mode 100644 index 000000000..815de35e1 --- /dev/null +++ b/install-dev/upgrade/php/update_module_pagesnotfound.php @@ -0,0 +1,42 @@ + +* @copyright 2007-2012 PrestaShop SA +* @version Release: $Revision: 14012 $ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +function update_module_pagesnotfound() +{ + $id_pagesnotfound = (int)Db::getInstance()->getValue('SELECT id_module FROM `'._DB_PREFIX_.'module` WHERE name = \'pagesnotfound\''); + if ($id_pagesnotfound) + { + $id_hook = (int)Db::getInstance()->getValue('SELECT `id_hook` FROM `'._DB_PREFIX_.'hook` WHERE `name` = \'frontCanonicalRedirect\''); + if ($id_hook) + { + $position = (int)Db::getInstance()->getValue('SELECT IFNULL(MAX(`position`), 0) + 1 FROM `'._DB_PREFIX_.'hook_module` WHERE `id_hook` = '.(int)$id_hook); + if ($position) + return Db::getInstance()->Execute('INSERT IGNORE INTO `'._DB_PREFIX_.'hook_module` (`id_hook`, `id_module`, `position`) VALUES ('.(int)$id_hook.', '.(int)$id_pagesnotfound.', '.(int)$position.')'); + } + } + return true; +} \ No newline at end of file diff --git a/install-dev/upgrade/sql/1.4.9.0.sql b/install-dev/upgrade/sql/1.4.9.0.sql new file mode 100644 index 000000000..3f03b2ccf --- /dev/null +++ b/install-dev/upgrade/sql/1.4.9.0.sql @@ -0,0 +1,27 @@ +SET NAMES 'utf8'; + +ALTER TABLE `PREFIX_image` ADD UNIQUE KEY `idx_product_image` (`id_image` , `id_product` , `cover`); + +/* PHP:clean_category_product(); */; +ALTER TABLE `PREFIX_category_product` DROP INDEX `category_product_index`, ADD PRIMARY KEY (`id_category`, `id_product`); + +ALTER TABLE `PREFIX_cms_category_lang` DROP INDEX `category_lang_index`, ADD PRIMARY KEY (`id_cms_category`, `id_lang`); +ALTER TABLE `PREFIX_order_tax` ADD `id_order_tax` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST; +ALTER TABLE `PREFIX_feature_lang` ADD INDEX feature_name (`id_lang`, `name`); +ALTER TABLE `PREFIX_state` ADD INDEX statename (`name`); +ALTER TABLE `PREFIX_category` ADD INDEX nleftrightactive (`nleft`, `nright`, `active`); +ALTER TABLE `PREFIX_category` ADD INDEX level_depth (`level_depth`); +ALTER TABLE `PREFIX_category` ADD INDEX nright (`nright`); +ALTER TABLE `PREFIX_category` ADD INDEX nleft (`nleft`); +ALTER TABLE `PREFIX_specific_price` ADD INDEX from_quantity (`from_quantity`); +ALTER TABLE `PREFIX_product` ADD INDEX indexed (`indexed`); + +UPDATE `PREFIX_country` SET `zip_code_format` = 'NNNNN' WHERE `iso_code` = 'MC' LIMIT 1; +UPDATE `PREFIX_county_zip_code` SET `to_zip_code` = `from_zip_code` WHERE `to_zip_code` = 0; +UPDATE `PREFIX_configuration` SET `value` = 0 WHERE `name` = 'PS_HIGH_HTML_THEME_COMPRESSION' LIMIT 1; + +INSERT INTO `PREFIX_configuration` (`name`, `value`, `date_add`, `date_upd`)(SELECT 'PS_TAX_DISPLAY_ALL', `value`, NOW(), NOW() FROM `PREFIX_configuration` WHERE name = 'PS_TAX_DISPLAY' LIMIT 1); + +DELETE FROM `PREFIX_referrer_cache` WHERE id_referrer NOT IN (SELECT id_referrer FROM `PREFIX_referrer`); + +/* PHP:update_module_blocklayered(); */; \ No newline at end of file diff --git a/install-dev/upgrade/sql/1.4.9.1.sql b/install-dev/upgrade/sql/1.4.9.1.sql new file mode 100644 index 000000000..7ba82b218 --- /dev/null +++ b/install-dev/upgrade/sql/1.4.9.1.sql @@ -0,0 +1,3 @@ +SET NAMES 'utf8'; + +/* PHP:update_module_mailalerts(); */; \ No newline at end of file