Monday, July 30, 2012

Upgrading magento from 1.4.1.1 to 1.6.0.0 (issue with upgrading databse)

If found issue with query "ALTER TABLE `sales_flat_order` ADD UNIQUE `UNQ_INCREMENT_ID` ( `increment_id` )" and taking a long time at this stage than need to find duplicate entires..

try this...

find duplicate increment ids..
SELECT increment_id, COUNT(*) c FROM sales_flat_order GROUP BY increment_id HAVING c > 1;

create new file on root and run below code..

require 'app/Mage.php';
Mage::app('admin');

 $dupes= array('R00168293-1','R00168534-1','R00168946-1');

Mage::getSingleton("core/session", array("name" => "adminhtml"));
Mage::register('isSecureArea',true);
$collection = Mage::getResourceModel('sales/order_collection')
  ->addAttributeToSelect('*')
  ->setPageSize(5000)
  ->addFieldToFilter('status', 'canceled')
  ->addFieldToFilter('increment_id', array('in'=>$dupes))
  ->load();

foreach ($collection as $col) {
  Mage::log($col->getIncrementId() . ' order deleted ');
  try {
    $col->delete();
  } catch (Exception $e) {
    throw $e;
  }
}

No comments:

Post a Comment