00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 $installer = $this;
00028
00029
00030 $installer->startSetup();
00031
00032 $conn = $installer->getConnection();
00033 $websites = $conn->fetchPairs("SELECT store_id, website_id FROM {$installer->getTable('core_store')}");
00034 $ruleTable = $this->getTable('catalogrule');
00035 if ($conn->tableColumnExists($ruleTable, 'store_ids')) {
00036
00037 $conn->addColumn($ruleTable, 'website_ids', 'text');
00038 $select = $conn->select()
00039 ->from($ruleTable, array('rule_id', 'store_ids'));
00040 $rows = $conn->fetchAll($select);
00041
00042 foreach ($rows as $r) {
00043 $websiteIds = array();
00044 foreach (split(',', $r['store_ids']) as $storeId) {
00045 if (($storeId!=='') && isset($websites[$storeId])) {
00046 $websiteIds[$websites[$storeId]] = true;
00047 }
00048 }
00049
00050 $conn->update($ruleTable, array('website_ids'=>join(',',array_keys($websiteIds))), "rule_id=".$r['rule_id']);
00051 }
00052 $conn->dropColumn($ruleTable, 'store_ids');
00053 }
00054
00055
00056 $ruleProductTable = $this->getTable('catalogrule_product');
00057 if ($conn->tableColumnExists($ruleProductTable, 'store_id')) {
00058 $conn->addColumn($ruleProductTable, 'website_id', 'smallint unsigned not null');
00059 $unique = array();
00060
00061 $select = $conn->select()
00062 ->from($ruleProductTable);
00063 $rows = $conn->fetchAll($select);
00064
00065
00066 foreach ($rows as $r) {
00067 $websiteId = $websites[$r['store_id']];
00068 $key = $r['from_time'].'|'.$r['to_time'].'|'.$websiteId.'|'.$r['customer_group_id'].'|'.$r['product_id'].'|'.$r['sort_order'];
00069 if (isset($unique[$key])) {
00070 $conn->delete($ruleProductTable, $conn->quoteInto("rule_product_id=?", $r['rule_product_id']));
00071 } else {
00072 $conn->update($ruleProductTable, array('website_id'=>$websiteId), "rule_product_id=".$r['rule_product_id']);
00073 $unique[$key] = true;
00074 }
00075 }
00076 $conn->dropKey($ruleProductTable, 'sort_order');
00077 $conn->raw_query("ALTER TABLE `$ruleProductTable` ADD UNIQUE KEY `sort_order` (`from_time`,`to_time`,`website_id`,`customer_group_id`,`product_id`,`sort_order`)");
00078
00079 $conn->dropForeignKey($ruleProductTable, 'FK_catalogrule_product_store');
00080 $conn->dropColumn($ruleProductTable, 'store_id');
00081
00082 $conn->dropForeignKey($ruleProductTable, 'FK_catalogrule_product_website');
00083 $conn->raw_query("ALTER TABLE `$ruleProductTable` ADD CONSTRAINT `FK_catalogrule_product_website` FOREIGN KEY (`website_id`) REFERENCES `{$this->getTable('core_website')}` (`website_id`) ON DELETE CASCADE ON UPDATE CASCADE");
00084 }
00085
00086
00087
00088 $ruleProductPriceTable = $this->getTable('catalogrule_product_price');
00089 if ($conn->tableColumnExists($ruleProductPriceTable, 'store_id')) {
00090 $conn->addColumn($ruleProductPriceTable, 'website_id', 'smallint unsigned not null');
00091 $conn->delete($ruleProductPriceTable);
00092
00093 $conn->dropKey($ruleProductPriceTable, 'rule_date');
00094 $conn->raw_query("ALTER TABLE `$ruleProductPriceTable` ADD UNIQUE KEY `rule_date` (`rule_date`,`website_id`,`customer_group_id`,`product_id`)");
00095
00096 $conn->dropForeignKey($ruleProductPriceTable, 'FK_catalogrule_product_store');
00097 $conn->dropColumn($ruleProductPriceTable, 'store_id');
00098
00099 $conn->dropForeignKey($ruleProductPriceTable, 'FK_catalogrule_product_price_website');
00100 $conn->raw_query("ALTER TABLE `$ruleProductPriceTable` ADD CONSTRAINT `FK_catalogrule_product_price_website` FOREIGN KEY (`website_id`) REFERENCES `{$this->getTable('core_website')}` (`website_id`) ON DELETE CASCADE ON UPDATE CASCADE");
00101 }
00102
00103 $installer->endSetup();