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 $tableOrder = $this->getTable('sales/order');
00031 $tableOrderEntity = $this->getTable('sales/order_entity');
00032
00033 $cleanTables = array(
00034 $tableOrder . '_datetime',
00035 $tableOrder . '_decimal',
00036 $tableOrder . '_int',
00037 $tableOrder . '_text',
00038 $tableOrder . '_varchar',
00039 $tableOrderEntity . '_decimal',
00040 $tableOrderEntity . '_datetime',
00041 $tableOrderEntity . '_int',
00042 $tableOrderEntity . '_text',
00043 $tableOrderEntity . '_varchar'
00044 );
00045 foreach ($cleanTables as $tableName) {
00046 $select = $installer->getConnection()->select()
00047 ->from($tableName, array(
00048 'entity_id' => 'entity_id',
00049 'attribute_id' => 'attribute_id',
00050 'entity_type_id' => 'entity_type_id',
00051 'rows_count' => 'COUNT(*)'))
00052 ->group(array('entity_id', 'attribute_id', 'entity_type_id'))
00053 ->having('rows_count > 1');
00054 $query = $installer->getConnection()->query($select);
00055
00056 while ($row = $query->fetch()) {
00057 $sql = 'DELETE FROM `' . $tableName . '`'
00058 . ' WHERE entity_id=? AND attribute_id=? AND entity_type_id=?'
00059 . ' LIMIT ' . ($row['rows_count'] - 1);
00060 $installer->getConnection()->query($sql, array(
00061 $row['entity_id'],
00062 $row['attribute_id'],
00063 $row['entity_type_id']
00064 ));
00065 }
00066 }
00067
00068 $installer->getConnection()->addKey("{$tableOrder}_datetime", 'UNQ_ENTITY_ATTRIBUTE_TYPE', array('entity_id', 'attribute_id', 'entity_type_id'), 'unique');
00069 $installer->getConnection()->addKey("{$tableOrder}_decimal", 'UNQ_ENTITY_ATTRIBUTE_TYPE', array('entity_id', 'attribute_id', 'entity_type_id'), 'unique');
00070 $installer->getConnection()->addKey("{$tableOrder}_int", 'UNQ_ENTITY_ATTRIBUTE_TYPE', array('entity_id', 'attribute_id', 'entity_type_id'), 'unique');
00071 $installer->getConnection()->addKey("{$tableOrder}_text", 'UNQ_ENTITY_ATTRIBUTE_TYPE', array('entity_id', 'attribute_id', 'entity_type_id'), 'unique');
00072 $installer->getConnection()->addKey("{$tableOrder}_varchar", 'UNQ_ENTITY_ATTRIBUTE_TYPE', array('entity_id', 'attribute_id', 'entity_type_id'), 'unique');
00073
00074 $installer->getConnection()->addKey("{$tableOrderEntity}_datetime", 'UNQ_ENTITY_ATTRIBUTE_TYPE', array('entity_id', 'attribute_id', 'entity_type_id'), 'unique');
00075 $installer->getConnection()->addKey("{$tableOrderEntity}_decimal", 'UNQ_ENTITY_ATTRIBUTE_TYPE', array('entity_id', 'attribute_id', 'entity_type_id'), 'unique');
00076 $installer->getConnection()->addKey("{$tableOrderEntity}_int", 'UNQ_ENTITY_ATTRIBUTE_TYPE', array('entity_id', 'attribute_id', 'entity_type_id'), 'unique');
00077 $installer->getConnection()->addKey("{$tableOrderEntity}_text", 'UNQ_ENTITY_ATTRIBUTE_TYPE', array('entity_id', 'attribute_id', 'entity_type_id'), 'unique');
00078 $installer->getConnection()->addKey("{$tableOrderEntity}_varchar", 'UNQ_ENTITY_ATTRIBUTE_TYPE', array('entity_id', 'attribute_id', 'entity_type_id'), 'unique');
00079
00080 $installer->getConnection()->addKey($tableOrderEntity, 'IDX_SALES_ORDER_ENTITY_PARENT', 'parent_id');