[Vtigercrm-developers] PBXManager Migration Script

Alan Lord (News) alanslists at gmail.com
Mon Feb 16 18:00:55 GMT 2015


I am completely baffled by this piece of code in the 600_to_610 
migration file.

> //Data migrate from old columns to new columns in vtiger_pbxmanager
> $query = 'SELECT * FROM vtiger_pbxmanager';
> $result = $adb->pquery($query, array());
> $params = array();
> $rowCount = $adb->num_rows($result);
> for ($i = 0; $i < $rowCount; $i++) {
>     $pbxmanagerid = $adb->query_result($result, $i, 'pbxmanagerid');

>     $callfrom = $adb->query_result($result, $i, 'callfrom');
In most of our customers' vtiger systems this column contains the vtiger 
user's Firstname & Lastname as a string. It does *not* contain a phone 
number.

>     $callto = $adb->query_result($result, $i, 'callto');
This contains the html markup for the target module's detail view link.

>     $timeofcall = $adb->query_result($result, $i, 'timeofcall');
This is a mysql datetime value.

>     $status = $adb->query_result($result, $i, 'status');
Mostly "outgoing" in our cases.

>     $customer = PBXManager_Record_Model::lookUpRelatedWithNumber($callfrom);
So this line appears to be trying to get the crmid of the customer. I 
see several problems with it:

1. It is only ever going to work for incoming calls where the callfrom 
might be populated with a Contact Name or number.

2. The function in the Record model is expecting to be passed a number, 
not a name so it's a complete waste of time for outgoing calls.

3. The function in the Record model returns an array. So $customer will 
be an array.

>     $userIdQuery = $adb->pquery('SELECT userid FROM vtiger_asteriskextensions WHERE asterisk_extension = ?', array($callto));
>     $user = $adb->query_result($userIdQuery, $i, 'userid');
>     if ($status == 'outgoing') {
>         $callstatus = 'outbound';
>     } else if ($status == 'incoming') {
>         $callstatus = 'inbound';
>     }
>     //Update query
>     $adb->pquery('UPDATE vtiger_pbxmanager SET customer = ? AND user = ? AND totalduration = ? AND callstatus = ? WHERE pbxmanagerid = ?', array($customer, $user, $timeofcall, $callstatus, $pbxmanagerid));
This line is trying to save an array ($customer) into the customer 
column of vtiger_pbxmanager which is a varchar(100) type column...

It is also trying to save a datetime value ($timeofcall) into the 
totalduration column which is an integer type column..

It seems to me that this snippet of code will never really do anything 
useful. And when you have a vtiger_pbxmanager table with nearly 500,000 
rows of outbound call records it spends an awfully long time doing 
absolutely nothing...

Is it me or is this all completely bonkers?



Al


-- 
Libertus Solutions
http://www.libertus.co.uk



More information about the vtigercrm-developers mailing list