Results 1 to 2 of 2

Thread: Importing Error

  1. #1
    Odie2828 is offline Junior Member
    Join Date
    Apr 2011
    Posts
    4

    Default Importing Error

    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($querytrue"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($query2true"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($querytrue"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($query2true"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!

  2. #2
    kuske's Avatar
    kuske is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Germany
    Posts
    2,597

    Default Re: Importing Error

    All these fields for the parent in $_REQUEST can be set but the need not.

    So just calculate the parent on the fly in a after_save (not before_save)logic hook with one sql statement like that:

    $sql = "update contacts_cstm c
    left join accounts_contacts ac on c.id_c=ac.contact_id and ac.deleted=0
    left join accounts_cstm a on a.id_c=ac.account_id
    set c.last_touched_c = now(),
    a.last_touched_c = now()
    where c.id_c='". $bean.id."';";
    Harald Kuske
    Pre-Sales Engineer Central Europe

    SUGARCRM Deutschland GmbH
    Erika-Mann-Str. 53, 80636 Munich, Germany
    Email: hkuske@sugarcrm.com
    Home: http://www.sugarcrm.com


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Error when importing - is this a bug?
    By paradilly in forum Developer Help
    Replies: 2
    Last Post: 2010-12-13, 03:11 PM
  2. Error on Importing!
    By m3suriya in forum Developer Help
    Replies: 8
    Last Post: 2010-06-26, 08:28 PM
  3. Error while importing
    By k.divya in forum Developer Help
    Replies: 6
    Last Post: 2009-04-21, 05:40 PM
  4. Error while importing
    By ramyaccs in forum Developer Help
    Replies: 0
    Last Post: 2008-07-03, 04:53 AM
  5. Error upon importing
    By jdev in forum Help
    Replies: 0
    Last Post: 2006-03-03, 02:03 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •