Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: how to audit in contact module the account field

  1. #1
    bgoubin is offline Junior Member
    Join Date
    Apr 2008
    Posts
    2

    Default how to audit in contact module the account field

    I am in Version 4.5.1i (Build 1176) and i have modified the varsdef.php in the contact module to set 'audited'=>true for the fields account_name and account_id but when i change a account name for a contact nothing was audited in the changelog windows.

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

    Default Re: how to audit in contact module the account field

    1st you should wite 'true' insted of true.

    2nd there is a bug in /include/database/DBHelper.php:

    The function getDataChanges only tests changes of fields which are columns in <bean> and <bean>_cstm tables (listed in fetched_row array), not the related fields (listed in rel_fields_before_value array)!

    I made a simple quick change (without any guarantees!) of this function by duplicating the code.
    In the new PATCH code not only the fetched_rows array is checked but also the rel_fields_before_value array.

    Code:
    	function getDataChanges(&$bean) {
    
    		$changed_values=array();
    		$audit_fields=$bean->getAuditEnabledFieldDefinitions();
    
    		if (is_array($audit_fields) and count($audit_fields) > 0) {
    			foreach ($audit_fields as $field=>$properties) {
    
                if (!empty($bean->fetched_row) && array_key_exists($field, $bean->fetched_row)) {
    
                   $before_value=$bean->fetched_row[$field];
                   $after_value=$bean->$field;
                   if (isset($properties['type']))
                      $field_type=$properties['type'];
                   else {
                      if (isset($properties['dbType']))
                         $field_type=$properties['dbType'];
                      else if(isset($properties['data_type']))
                         $field_type=$properties['data_type'];
                      else
                         $field_type=$properties['dbtype'];
                   }
    
                   //if the type and values match, do nothing.
                   if (!(emptyValue($before_value,$field_type) && emptyValue($after_value,$field_type))) {
                      if (trim($before_value) !== trim($after_value)) {
                         if (!(isTypeNumber($field_type) && (trim($before_value)+0) == (trim($after_value)+0))) {
                            if (!(isTypeBoolean($field_type) && (getBooleanValue($before_value)== getBooleanValue($after_value)))) {
                               $changed_values[$field]=array('field_name'=>$field,
                                  'data_type'=>$field_type,
                                  'before'=>$before_value,
                                  'after'=>$after_value);
                            }
                         }
                      }
                   }
                }
    //PATCH BEGIN KUSKE_151            
                if (!empty($bean->rel_fields_before_value) && array_key_exists($field, $bean->rel_fields_before_value)) {
    
                   $before_value=$bean->rel_fields_before_value[$field];
                   $after_value=$bean->$field;
                   if (isset($properties['type']))
                      $field_type=$properties['type'];
                   else {
                      if (isset($properties['dbType']))
                         $field_type=$properties['dbType'];
                      else if(isset($properties['data_type']))
                         $field_type=$properties['data_type'];
                      else
                         $field_type=$properties['dbtype'];
                   }
    
                   //if the type and values match, do nothing.
                   if (!(emptyValue($before_value,$field_type) && emptyValue($after_value,$field_type))) {
                      if (trim($before_value) !== trim($after_value)) {
                         if (!(isTypeNumber($field_type) && (trim($before_value)+0) == (trim($after_value)+0))) {
                            if (!(isTypeBoolean($field_type) && (getBooleanValue($before_value)== getBooleanValue($after_value)))) {
                               $changed_values[$field]=array('field_name'=>$field,
                                  'data_type'=>$field_type,
                                  'before'=>$before_value,
                                  'after'=>$after_value);
                            }
                         }
                      }
                   }
                }
    //PATCH END KUSKE_151            
    			}
    		}
    		return $changed_values;
    	}
    I changed this in version 4.5.1h, I do not know yet whether the bug is in 5.0.0 too....
    Last edited by kuske; 2008-04-18 at 04:01 PM.

  3. #3
    bgoubin is offline Junior Member
    Join Date
    Apr 2008
    Posts
    2

    Default Re: how to audit in contact module the account field

    Thank you for your reply, the account_id field is now audited with your patch on a sugarcrm 5.0

  4. #4
    ddaavvee is offline Sugar Community Member
    Join Date
    Jan 2008
    Posts
    10

    Default Re: how to audit in contact module the account field

    Ah, super fix. Life saver!

  5. #5
    Denzel is offline Sugar Community Member
    Join Date
    Jan 2008
    Posts
    12

    Default Re: how to audit in contact module the account field

    This isn't fixed in 5.0 and not in 5.1.

    Isn't it possible to integrate this in Sugar as default?

    Greetings, Dennis

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

    Default Re: how to audit in contact module the account field

    good question....
    does anyone want to open a bug?
    or is it already a reported bug?

  7. #7
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: how to audit in contact module the account field

    Quote Originally Posted by Denzel
    This isn't fixed in 5.0 and not in 5.1.

    Isn't it possible to integrate this in Sugar as default?

    Greetings, Dennis
    Hi Denzel

    Submit a new bug (feature) into bugs.sugarcrm.com requesting this feature.

    Cheers
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

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

    Default Re: how to audit in contact module the account field

    Addendum:
    The patch works in 5.1.0c and it works in 5.2.0...

    Do not forget to set the

    'audited'=>'true',

    lines in vardefs.php

  9. #9
    dricrm is offline Sugar Community Member
    Join Date
    Aug 2005
    Location
    Lisbon, Portugal
    Posts
    116

    Default Re: how to audit in contact module the account field

    Hi,

    I tried this with no success in 5.2.0a, but I've come up with a solution to my specific need which may be adapted to other situations. It's not very clean or performant, I guess, but it get's the job done.

    In modules/Audit/Audit.php:135 add an elseif clause

    PHP Code:
    elseif (($field ['name'] == 'before_value_string' || $field ['name'] == 'after_value_string') && $row ['field_name'] == "employee_id") {
        
    $q "SELECT concat_ws(' ', first_name, last_name) from users where id='{$temp_list [$field ['name']]}' and deleted=0";
        
    $n $GLOBALS['db']->getOne($q);
            
    $temp_list [$field ['name']] = $n;

    And then audit the ID field itself, not the related one.

    I guess this could be expanded to pickup on other ID fields that had a certain attribute back to whichever related type field you want to audit them against.

    Cheers
    diogo

  10. #10
    datasponge is offline Sugar Community Member
    Join Date
    Mar 2008
    Location
    San Jose, CA, USA
    Posts
    553

    Default Re: how to audit in contact module the account field

    diogo,

    Thanks for the tip. See my question below.

    Quote Originally Posted by dricrm View Post
    Hi,

    I tried this with no success in 5.2.0a, but I've come up with a solution to my specific need which may be adapted to other situations. It's not very clean or performant, I guess, but it get's the job done.

    In modules/Audit/Audit.php:135 add an elseif clause

    PHP Code:
    elseif (($field ['name'] == 'before_value_string' || $field ['name'] == 'after_value_string') && $row ['field_name'] == "employee_id") {
        
    $q "SELECT concat_ws(' ', first_name, last_name) from users where id='{$temp_list [$field ['name']]}' and deleted=0";
        
    $n $GLOBALS['db']->getOne($q);
            
    $temp_list [$field ['name']] = $n;

    And then audit the ID field itself, not the related one.

    I guess this could be expanded to pickup on other ID fields that had a certain attribute back to whichever related type field you want to audit them against.

    Cheers
    diogo
    I wanted to apply this to auditing email addresses through Contacts or Accounts, but I'm not understanding something:

    I don't see how '{$temp_list [$field ['name']]}' is ever set before defining the query since it is only referenced in the if condition above your elseif.

    Is employee_id a custom field you added to the Users module (and defined in vardefs.php)? I'm trying to understand what field I have to replace there, since my situation involves multiple tables.

    If I'm following your logic, I could reference the field 'email_addresses' in the elseif condition, then match the id field for my module (e.g. contacts.id) then query for the email address for that bean_id in order to audit email changes from the Contacts module.

    Any tips would be appreciated.

    Phil

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 3
    Last Post: 2007-12-05, 06:18 PM
  2. Individual Contact NO associated Account Module
    By directjj in forum Feature Requests
    Replies: 0
    Last Post: 2006-04-07, 05:09 PM
  3. Module Cases: missing field 'Contact'
    By kaoAndyBe in forum General Discussion
    Replies: 0
    Last Post: 2006-03-30, 03:44 AM
  4. Adding custom field when creating module.
    By Superman in forum General Discussion
    Replies: 1
    Last Post: 2005-11-16, 07:30 AM

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
  •