VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: manburg6 on July 19, 2012, 13:56:45 PM

Title: Order migration - Date
Post by: manburg6 on July 19, 2012, 13:56:45 PM
Hello,

I'm migrating my Joomla 1.5 and VM 1.1.9 to new version.

I've found an error during order migration:

all the old order, migrated to VM 2.0.8, are with "Order Date" and "Last Modified Date" set to migration time.
Shold be copied with the original order date.

Any suggestion?

Thanks,
Mario
Title: Re: Order migration - Date
Post by: klattr1 on November 02, 2012, 03:58:58 AM
I've also had the same issue. Is there a fix?
Title: Re: Order migration - Date
Post by: xpozay on January 08, 2013, 09:19:56 AM
Having the same problem with VM 2.0.16d except that the order date is correct.  However, the last modified date / all the history of events dates are set to the migration date.

History of events is when the order changes from pending to confirmed to shipped, etc.  All these dates are modified.

Is there a configuration setting that resolves this?  Or was this fixed?

I also found this thread but checked migrator and it is already written like suggested.

I previously found this http://forum.virtuemart.net/index.php?topic=106574.msg355695#msg355695 but can see this is already in migrator.php
Title: Re: Order migration - Date
Post by: Milbo on January 08, 2013, 14:46:13 PM
We use this,


$orderData->created_on = $this->_changeToStamp($order['cdate']);
$orderData->modified_on = $this->_changeToStamp($order['mdate']); //we could remove this to set modified_on today


strange. Maybe you are not superadmin doing the migration.
Title: Re: Order migration - Date
Post by: xpozay on January 08, 2013, 15:56:59 PM
Yes my code is the same.  Also I have Super Admin access while doing the migration.

I did a little more digging and to be honest I am not sure how all the others have been successfully migrating.  Perhaps they are not really checking as this problem is not just with orders - it is for all of the tables: products, categories, orders.  I did not check media or anything else.

Orders

If you look at orders in migrator.php around line 1383
$orderData->created_on = $this->_changeToStamp($order['cdate']);
$orderData->modified_on = $this->_changeToStamp($order['mdate']); //we could remove this to set modified_on today


It appears to be OK however if you look at the table directly:
- in table created_on is ok
- in table modified_on is written as the time the migrator is run (should not be the case)

Next if you look at  order_item around line 1412
$item['created_on'] = $this->_changeToStamp($item['cdate']);
$item['modified_on'] = $this->_changeToStamp($item['mdate']); //we could remove this to set modified_on today

Similarly it looks OK but if you look at the table
- created_on is ok
- modified_on is migrator date (should not be the case)

Next if you look at orders history around line 1428
$q = 'SELECT * FROM `#__vm_order_history` WHERE `order_id` = "'.$order['order_id'].'" ';
$this->_db->setQuery($q);
$oldItems = $this->_db->loadAssocList();

foreach($oldItems as $item){
$item['virtuemart_order_id'] = $newId;
//$item['order_status_code'] = $orderCodeToId[$item['order_status_code']];


$orderHistoriesTable = $this->getTable('order_histories');
$orderHistoriesTable->bindChecknStore($item);
$errors = $orderHistoriesTable->getErrors();
if(!empty($errors)){
foreach($errors as $error){
$this->_app->enqueueMessage('Migration orderhistories: ' . $error);
}
$continue = false;
break;
}
}


There is no change of date format at all neither created_on or modified_on fields are converted to the new format and the dates are set to the date / time the migrate is run (should not be the case)


So why is it that for all the "mdates", they are written with the "today's" date / time ie date/time stamp the migrator is run?

After some searching I found the line 285 in vmtables
$this->modified_on = $today;

This line was setting all of the "mdates" to the date /time the migrator is being run.

For created_on dates ("cdate"), there is a check immediate about the $today statement
if($this->created_on=="0000-00-00 00:00:00"){
$this->created_on = $this->$today;

which does a check before writing.  It is correct to assume that this check should also be implemented on 'mdate' / modified_on fields?


I commented out that line ($this->modified_on = $today;) and the mdate started to show up in the tables but with some problems:
1) The date was not converted to the new format so all the dates were screwed up but not at least the migrator date.  I assume using the check like what is done on creatd_on will resolve this?

2) modified_date for order history is all set to 0000-00-00 00:00:00 because this field does not exist in the old vm tables.  This is logical as these records are never modified because they are status updates.  That said, it could also be logical to write the creation date there instead so that the created_on and the modified_on were the same.

Please advise me what and where should be changed to make this work properly.

Thanks

Also, for the setting of created_on date  = today in vmtables.php as shown above, I am not convinced this is correct either.  We are doing a migration and therefore there should be no changes to old data.  In fact, in many countries it would be illegal to modify historical records for audit and taxation purposes. 
Title: Re: Order migration - Date
Post by: xpozay on January 11, 2013, 11:46:51 AM
Got this working and found another thread too.

Hack is found here

http://forum.virtuemart.net/index.php?topic=105115.0