From 63e8827c1a860d3d01153bd9c8e50c438bb26aee Mon Sep 17 00:00:00 2001 From: mMarinetti Date: Sun, 20 May 2012 11:55:45 +0000 Subject: [PATCH] // fix table cms naming git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@15469 b9a71923-0436-4b27-9f14-aed3839534dd --- install-dev/upgrade/php/upgrade_cms_15.php | 14 ++++-- .../upgrade/php/upgrade_cms_15_rename.php | 50 +++++++++++++++++++ install-dev/upgrade/sql/1.5.0.12.sql | 1 + 3 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 install-dev/upgrade/php/upgrade_cms_15_rename.php diff --git a/install-dev/upgrade/php/upgrade_cms_15.php b/install-dev/upgrade/php/upgrade_cms_15.php index ed407cfd3..b276cc162 100644 --- a/install-dev/upgrade/php/upgrade_cms_15.php +++ b/install-dev/upgrade/php/upgrade_cms_15.php @@ -30,19 +30,27 @@ function upgrade_cms_15() $res = true; // note : cms_shop table is required and independant of blockcms module + // /!\ : _cms_shop is the wrong table name (fixed in 1.5.0.12.sql : upgrade_cms_15_rename() ) $res &= Db::getInstance()->execute('CREATE TABLE `'._DB_PREFIX_.'_cms_shop` ( `id_cms` INT( 11 ) UNSIGNED NOT NULL, `id_shop` INT( 11 ) UNSIGNED NOT NULL , PRIMARY KEY (`id_cms`, `id_shop`), KEY `id_shop` (`id_shop`) ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;'); - $res &= Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'_cms_shop` (id_shop, id_cms) (SELECT 1, id_cms FROM '._DB_PREFIX_.'_cms)'); + + // /!\ : _cms_shop and _cms are wrong tables name (fixed in 1.5.0.12.sql : upgrade_cms_15_rename() ) + $res &= Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'_cms_shop` (id_shop, id_cms) + (SELECT 1, id_cms FROM '._DB_PREFIX_.'_cms)'); // cms_block table is blockcms module dependant. Don't update table that does not exists - $id_module_cms = Db::getInstance()->getValue('SELECT id_module from `'._DB_PREFIX_.'_module where name="blockcms"`'); + // /!\ : _module is the wrong table name (fixed in 1.5.0.12.sql : upgrade_cms_15_rename() ) + $id_module_cms = Db::getInstance()->getValue('SELECT id_module from `'._DB_PREFIX_.'_module + WHERE name="blockcms"`'); if (!$id_module_cms) return $res; - $res &= Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'._cms_block` ADD `id_shop` INT(11) UNSIGNED NOT NULL DEFAULT "1" AFTER `id_cms_block`'); + // /!\ : _cms_block is the wrong table name (fixed in 1.5.0.12.sql : upgrade_cms_15_rename() ) + $res &= Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'._cms_block` + ADD `id_shop` INT(11) UNSIGNED NOT NULL DEFAULT "1" AFTER `id_cms_block`'); return $res; } diff --git a/install-dev/upgrade/php/upgrade_cms_15_rename.php b/install-dev/upgrade/php/upgrade_cms_15_rename.php new file mode 100644 index 000000000..36a9bf708 --- /dev/null +++ b/install-dev/upgrade/php/upgrade_cms_15_rename.php @@ -0,0 +1,50 @@ + +* @copyright 2007-2012 PrestaShop SA +* @version Release: $Revision: 15163 $ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ +function upgrade_cms_15_rename() +{ + $res = true; + $db = Db::getInstance(); + + $res &= $db->executeS('SHOW TABLES LIKE "'._DB_PREFIX_.'_cms_shop"'); + if ($res) + { + $res &= $db->execute('RENAME TABLE `'._DB_PREFIX_.'_cms_shop` to `'._DB_PREFIX_.'cms_shop`'); + // in case the script upgrade_cms_15.php have set a wrong table name, it's empty + $res &= Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'cms_shop` (id_shop, id_cms) + (SELECT 1, id_cms FROM '._DB_PREFIX_.'cms)'); + + // cms_block table is blockcms module dependant. Don't update table that does not exists + $id_module_cms = Db::getInstance()->getValue('SELECT id_module from `'._DB_PREFIX_.'module + WHERE name="blockcms"`'); + if (!$id_module_cms) + return $res; + $res &= Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'cms_block` ADD `id_shop` INT(11) UNSIGNED NOT NULL DEFAULT "1" AFTER `id_cms_block`'); + } + + return $res; +} diff --git a/install-dev/upgrade/sql/1.5.0.12.sql b/install-dev/upgrade/sql/1.5.0.12.sql index 78d5b6173..223bc7be7 100644 --- a/install-dev/upgrade/sql/1.5.0.12.sql +++ b/install-dev/upgrade/sql/1.5.0.12.sql @@ -51,3 +51,4 @@ CREATE TABLE IF NOT EXISTS `PREFIX_risk_lang` ( UPDATE `PREFIX_tab` SET `class_name`="AdminShopGroup" WHERE class_name="AdminGroupShop"; +/* PHP:upgrade_cms_15_rename(); */;