Exemplo n.º 1
0
 /**
  * Uses the audit enabled fields array to find fields whose value has changed.
  * The before and after values are stored in the bean.
  * Uses $bean->fetched_row && $bean->fetched_rel_row to compare
  *
  * @param SugarBean $bean Sugarbean instance that was changed
  * @return array
  */
 public function getAuditDataChanges(SugarBean $bean)
 {
     $audit_fields = $bean->getAuditEnabledFieldDefinitions();
     return $this->getDataChanges($bean, array_keys($audit_fields));
 }
Exemplo n.º 2
0
 /**
  * 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)) {
                 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'];
                         }
                     }
                 }
                 // Bug # 44624 - check for currency type and cast to float
                 // this ensures proper matching for change log
                 if (strcmp($field_type, "currency") == 0) {
                     $before_value = (double) $bean->fetched_row[$field];
                     $after_value = (double) $bean->{$field};
                 } else {
                     $before_value = $bean->fetched_row[$field];
                     $after_value = $bean->{$field};
                 }
                 //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 (!($this->_emptyValue($before_value, $field_type) && $this->_emptyValue($after_value, $field_type))) {
                     if (trim($before_value) !== trim($after_value)) {
                         // Bug #42475: Don't directly compare numeric values, instead do the subtract and see if the comparison comes out to be "close enough", it is necessary for floating point numbers.
                         if (!($this->_isTypeNumber($field_type) && abs(trim($before_value) + 0 - (trim($after_value) + 0)) < 0.001)) {
                             if (!($this->_isTypeBoolean($field_type) && $this->_getBooleanValue($before_value) == $this->_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'];
                         }
                     }
                 }
                 //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;
 }
Exemplo n.º 4
0
 /**
  * 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 (!($this->_emptyValue($before_value, $field_type) && $this->_emptyValue($after_value, $field_type))) {
                     if (trim($before_value) !== trim($after_value)) {
                         if (!($this->_isTypeNumber($field_type) && trim($before_value) + 0 == trim($after_value) + 0)) {
                             if (!($this->_isTypeBoolean($field_type) && $this->_getBooleanValue($before_value) == $this->_getBooleanValue($after_value))) {
                                 $changed_values[$field] = array('field_name' => $field, 'data_type' => $field_type, 'before' => $before_value, 'after' => $after_value);
                             }
                         }
                     }
                 }
             }
         }
     }
     return $changed_values;
 }
Exemplo n.º 5
0
 /**
  * Uses the audit enabled fields array to find fields whose value has changed.
  * The before and after values are stored in the bean.
  * Uses $bean->fetched_row to compare
  *
  * @param SugarBean $bean Sugarbean instance that was changed
  * @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 = $this->fromConvert($before_value, $field_type);
                 }
                 //if the type and values match, do nothing.
                 if (!($this->_emptyValue($before_value, $field_type) && $this->_emptyValue($after_value, $field_type))) {
                     if (trim($before_value) !== trim($after_value)) {
                         // Bug #42475: Don't directly compare numeric values, instead do the subtract and see if the comparison comes out to be "close enough", it is necessary for floating point numbers.
                         // Manual merge of fix 95727f2eed44852f1b6bce9a9eccbe065fe6249f from DBHelper
                         // This fix also fixes Bug #44624 in a more generic way and therefore eliminates the need for fix 0a55125b281c4bee87eb347709af462715f33d2d in DBHelper
                         if (!($this->isNumericType($field_type) && abs(2 * (trim($before_value) + 0 - (trim($after_value) + 0)) / (trim($before_value) + 0 + (trim($after_value) + 0))) < 1.0E-10)) {
                             // Smaller than 10E-10
                             if (!($this->isBooleanType($field_type) && $this->_getBooleanValue($before_value) == $this->_getBooleanValue($after_value))) {
                                 $changed_values[$field] = array('field_name' => $field, 'data_type' => $field_type, 'before' => $before_value, 'after' => $after_value);
                             }
                         }
                     }
                 }
             }
         }
     }
     return $changed_values;
 }