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); } } } } } } } return $changed_values; }
/** * Uses the audit enabled fields array to find fields whose value has changed. * The before and after values are stored in the bean. * * @param object $bean Sugarbean instance * @return array */ public function getDataChanges(SugarBean &$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']; } } } //Because of bug #25078(sqlserver haven't 'date' type, trim extra "00:00:00" when insert into *_cstm table). so when we read the audit datetime field from sqlserver, we have to replace the extra "00:00:00" again. if (!empty($field_type) && $field_type == 'date') { $before_value = from_db_convert($before_value, $field_type); } //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); } } } } } } } return $changed_values; }