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 $tableCatalogProduct = $this->getTable('catalog/product');
00031
00032 $types = array('datetime', 'decimal', 'int', 'text', 'varchar');
00033
00034 foreach ($types as $type) {
00035 $tableName = $tableCatalogProduct . '_' . $type;
00036
00037 $select = $installer->getConnection()->select()
00038 ->from($tableName, array(
00039 'entity_id' => 'entity_id',
00040 'attribute_id' => 'attribute_id',
00041 'store_id' => 'store_id',
00042 'rows_count' => 'COUNT(*)'))
00043 ->group(array('entity_id', 'attribute_id', 'store_id'))
00044 ->having('rows_count > 1');
00045 $query = $installer->getConnection()->query($select);
00046
00047 while ($row = $query->fetch()) {
00048 $sql = 'DELETE FROM `' . $tableName . '`'
00049 . ' WHERE entity_id=? AND attribute_id=? AND store_id=?'
00050 . ' LIMIT ' . ($row['rows_count'] - 1);
00051 $installer->getConnection()->query($sql, array(
00052 $row['entity_id'],
00053 $row['attribute_id'],
00054 $row['store_id']
00055 ));
00056 }
00057
00058 $installer->getConnection()->addKey($tableName, 'IDX_ATTRIBUTE_VALUE', array('entity_id', 'attribute_id', 'store_id'), 'unique');
00059 }
00060
00061
00062
00063 $tableName = $tableCatalogProduct . '_gallery';
00064
00065 $select = $installer->getConnection()->select()
00066 ->from($tableName, array(
00067 'entity_type_id' => 'entity_type_id',
00068 'entity_id' => 'entity_id',
00069 'attribute_id' => 'attribute_id',
00070 'store_id' => 'store_id',
00071 'rows_count' => 'COUNT(*)'))
00072 ->group(array('entity_id', 'attribute_id', 'store_id'))
00073 ->having('rows_count > 1');
00074 $query = $installer->getConnection()->query($select);
00075
00076 while ($row = $query->fetch()) {
00077 $sql = 'DELETE FROM `' . $tableName . '`'
00078 . ' WHERE entity_type_id=? AND entity_id=? AND attribute_id=? AND store_id=?'
00079 . ' LIMIT ' . ($row['rows_count'] - 1);
00080 $installer->getConnection()->query($sql, array(
00081 $row['entity_type_id'],
00082 $row['entity_id'],
00083 $row['attribute_id'],
00084 $row['store_id']
00085 ));
00086 }
00087
00088 $installer->getConnection()->addKey("{$tableCatalogProduct}_gallery", 'IDX_BASE', array('entity_type_id','entity_id','attribute_id','store_id'), 'unique');