/** * @param $table * * @return array */ protected function diffsInTable($table) { $rows = array(); $differ = new CRM_Logging_Differ($this->log_conn_id, $this->log_date, $this->interval); $diffs = $differ->diffsInTable($table, $this->cid); // return early if nothing found if (empty($diffs)) { return $rows; } list($titles, $values) = $differ->titlesAndValuesForTable($table); // populate $rows with only the differences between $changed and $original (skipping certain columns and NULL ↔ empty changes unless raw requested) $skipped = array('contact_id', 'entity_id', 'id'); foreach ($diffs as $diff) { $field = $diff['field']; $from = $diff['from']; $to = $diff['to']; if ($this->raw) { $field = "{$table}.{$field}"; } else { if (in_array($field, $skipped)) { continue; } // $differ filters out === values; for presentation hide changes like 42 → '42' if ($from == $to) { continue; } // special-case for multiple values. Also works for CRM-7251: preferred_communication_method if (substr($from, 0, 1) == CRM_Core_DAO::VALUE_SEPARATOR && substr($from, -1, 1) == CRM_Core_DAO::VALUE_SEPARATOR || substr($to, 0, 1) == CRM_Core_DAO::VALUE_SEPARATOR && substr($to, -1, 1) == CRM_Core_DAO::VALUE_SEPARATOR) { $froms = $tos = array(); foreach (explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($from, CRM_Core_DAO::VALUE_SEPARATOR)) as $val) { $froms[] = CRM_Utils_Array::value($val, $values[$field]); } foreach (explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($to, CRM_Core_DAO::VALUE_SEPARATOR)) as $val) { $tos[] = CRM_Utils_Array::value($val, $values[$field]); } $from = implode(', ', array_filter($froms)); $to = implode(', ', array_filter($tos)); } if (isset($values[$field][$from])) { $from = $values[$field][$from]; } if (isset($values[$field][$to])) { $to = $values[$field][$to]; } if (isset($titles[$field])) { $field = $titles[$field]; } if ($diff['action'] == 'Insert') { $from = ''; } if ($diff['action'] == 'Delete') { $to = ''; } } $rows[] = array('field' => $field . " (id: {$diff['id']})", 'from' => $from, 'to' => $to); } return $rows; }
/** * @param $table * * @return array */ protected function diffsInTable($table) { $this->setDiffer(); return $this->differ->diffsInTable($table, $this->cid); }