diff --git a/install-dev/upgrade/php/p15017_add_id_shop_to_primary_key.php b/install-dev/upgrade/php/p15017_add_id_shop_to_primary_key.php index 964da1b6a..c608fb030 100644 --- a/install-dev/upgrade/php/p15017_add_id_shop_to_primary_key.php +++ b/install-dev/upgrade/php/p15017_add_id_shop_to_primary_key.php @@ -27,10 +27,21 @@ function p15017_add_id_shop_to_primary_key() { + // Drop old indexes + $old_indexes = array( + 'category_lang_index' => 'category_lang', + 'shipper_lang_index' => 'carrier_lang', + 'product_lang_index' => 'product_lang' + ); + foreach ($old_indexes as $index => $table) + if (Db::getInstance()->executeS('SHOW INDEX FROM `'._DB_PREFIX_.$table.'` WHERE Key_name = "'.$index.'"')) + Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.$table.'` DROP KEY `'.$index.'`'); + // The former primary keys where set on id_object and id_lang. They must now be set on id_shop too. foreach (array('product', 'category', 'meta', 'carrier') as $table) { - Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.$table.'_lang` DROP PRIMARY KEY'); + if (Db::getInstance()->executeS('SHOW INDEX FROM `'._DB_PREFIX_.$table.'` WHERE Key_name = "PRIMARY"')) + Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.$table.'_lang` DROP PRIMARY KEY'); Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.$table.'_lang` ADD PRIMARY KEY (`id_'.$table.'`, `id_shop`, `id_lang`)'); }