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 $tableCustomer =
00031 $tableCustomerAddress = $this->getTable('customer/address_entity');
00032
00033 $types = array('datetime', 'decimal', 'int', 'text', 'varchar');
00034
00035 $tables = array($this->getTable('customer/entity'),
00036 $this->getTable('customer/address_entity'));
00037
00038 foreach ($tables as $table) {
00039 foreach ($types as $type) {
00040 $tableName = $table . '_' . $type;
00041
00042 $select = $installer->getConnection()->select()
00043 ->from($tableName, array(
00044 'entity_id' => 'entity_id',
00045 'attribute_id' => 'attribute_id',
00046 'rows_count' => 'COUNT(*)'))
00047 ->group(array('entity_id', 'attribute_id'))
00048 ->having('rows_count > 1');
00049 $query = $installer->getConnection()->query($select);
00050
00051 while ($row = $query->fetch()) {
00052 $sql = 'DELETE FROM `' . $tableName . '`'
00053 . ' WHERE entity_id=? AND attribute_id=?'
00054 . ' LIMIT ' . ($row['rows_count'] - 1);
00055 $installer->getConnection()->query($sql, array(
00056 $row['entity_id'],
00057 $row['attribute_id']
00058 ));
00059 }
00060
00061 $installer->getConnection()->addKey($tableName, 'IDX_ATTRIBUTE_VALUE', array('entity_id', 'attribute_id'), 'unique');
00062 }
00063 }