[Vtigercrm-developers] Another migration script query...

Alan Lord alanslists at gmail.com
Thu Mar 3 15:05:01 GMT 2016


In 540_to_600RC.php there are two sequences of code which move comments 
from vtiger_ticketcomments and faqcomments into the standard ModComments 
module.

Here is a bit of this code:

> 	for($i=0; $i<$rows; $i++) {

> 		$modComments = CRMEntity::getInstance('ModComments');

> 		$modComments->column_fields['commentcontent'] = decode_html($adb->query_result($ticketComments, $i, 'comments'));

> 		$ownerId = $adb->query_result($ticketComments, $i, 'ownerid');

> 		$current_user->id = $ownerId;

> 		$modComments->column_fields['assigned_user_id'] = $modComments->column_fields['creator'] = $ownerId;

> 		$modComments->column_fields['createdtime'] = $adb->query_result($ticketComments, $i, 'createdtime');

> 		$modComments->column_fields['modifiedtime'] = $adb->query_result($ticketComments, $i, 'createdtime');

> 		$modComments->column_fields['related_to'] = $adb->query_result($ticketComments, $i, 'ticketid');

> 		$modComments->save('ModComments');

> 		Migration_Index_View::ExecuteQuery('UPDATE vtiger_crmentity SET modifiedtime = ?, smcreatorid = ?, modifiedby = ? WHERE crmid = ?',

> 			array($modComments->column_fields['createdtime'], $ownerId, $ownerId, $modComments->id));

> 	}

It is *really* slow. Using the server API would be heaps quicker.

I was somewhat confused by the ownership part of this. I now see that it 
can include a Contact id in the vtiger_crmentity table. This was 
something I just learned and perhaps others will find it helpful...

In the last part of the loop, I think you should also be setting the 
createdtime in vtiger_crmentity or else it will almost certainly be 
ahead of the modifedtime.

HTH

Al



More information about the vtigercrm-developers mailing list