I have a Logic Hook created to update the "Last Touched" field anytime something within a contact is changed.
logic_hooks.php
PHP Code:
$hook_version = 1;
$hook_array = Array();
$hook_array['before_save'][] = Array(1, 'Accounts last touched', 'custom/modules/Contacts/lasttouchsave.php','LastTouchBase', 'updateLastTouch');
Here is the custom module:
lasttouchsave.php
PHP Code:
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class LastTouchBase
{
var $module = 'Contacts';
function updateLastTouch(&$bean, $event, $arguments)
{
if ($_REQUEST['relate_to']=='Contacts' && !empty($_REQUEST['relate_id'])) {
$query = "UPDATE contacts_cstm SET last_touched_c='".date('Y-m-d H:i:s')."' WHERE id_c='".$_REQUEST['relate_id']."'";
$bean->db->query($query, true, "Error updating Contacts - last touched: ");
}
if ($bean->parent_type=='Accounts') {
$query2 = "UPDATE accounts_cstm SET last_touched_c='".date('Y-m-d H:i:s')."' WHERE id_c='".$bean->parent_id."'";
$bean->db->query($query2, true, "Error updating Accounts - last touched:");
} elseif ($bean->parent_type=='Contacts') {
$query = "UPDATE contacts_cstm SET last_touched_c='".date('Y-m-d H:i:s')."' WHERE id_c='".$bean->parent_id."'";
$bean->db->query($query, true, "Error updating Contacts - last touched: ");
$accQuery = "SELECT account_id FROM accounts_contacts WHERE contact_id='".$bean->parent_id."' LIMIT 0,1";
$accResult = $bean->db->query($accQuery);
$accRow = $bean->db->fetchByAssoc($accResult);
if ($accRow) {
$account_id = $accRow['account_id'];
$query2 = "UPDATE accounts_cstm SET last_touched_c='".date('Y-m-d H:i:s')."' WHERE id_c='".$account_id."'";
$bean->db->query($query2, true, "Error updating Accounts - last touched:");
}
}
}
}
When importing Contacts, this is the error that i receive:
NOTICE: [8] Undefined property: Contact::$parent_type on line 8 in file /var/www/html/CDISugarCE_Test/custom/modules/Contacts/lasttouchsave.php
NOTICE: [8] Undefined index: relate_to on line 9 in file /var/www/html/CDISugarCE_Test/custom/modules/Contacts/lasttouchsave.php
NOTICE: [8] Undefined property: Contact::$parent_type on line 13 in file /var/www/html/CDISugarCE_Test/custom/modules/Contacts/lasttouchsave.php
NOTICE: [8] Undefined property: Contact::$parent_type on line 16 in file /var/www/html/CDISugarCE_Test/custom/modules/Contacts/lasttouchsave.php
Any ideas?
Maybe something to do with the latest patch? Version 6.2.0 (Build 6354)
Thank you in advance!
Bookmarks