'table_name' => 'log_civicrm_activity_contact',
'log_type' => 'Activity',
'field' => 'activity_id',
+ 'extra_joins' => array(
+ 'table' => 'log_civicrm_activity',
+ 'join' => 'extra_table.id = entity_log_civireport.activity_id',
+ ),
'bracket_info' => array(
'entity_column' => 'activity_type_id',
$this->_selectAliases[] = $alias;
return "activity_id";
}
+ if ($fieldName == 'log_grouping') {
+ if ($this->currentLogTable != 'log_civicrm_activity_contact') {
+ return 1;
+ }
+ $mergeActivityID = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Contact Merged');
+ return " IF (entity_log_civireport.log_action = 'Insert' AND extra_table.activity_type_id = $mergeActivityID , GROUP_CONCAT(entity_log_civireport.contact_id), 1) ";
+ }
}
public function where() {
$this->beginPostProcess();
$rows = array();
- $tempColumns = "id int(10)";
+ $tempColumns = "id int(10), log_civicrm_entity_log_grouping varchar(32)";
if (!empty($this->_params['fields']['log_action'])) {
$tempColumns .= ", log_action varchar(64)";
}
$sql = "{$this->_select}
FROM civicrm_temp_civireport_logsummary entity_log_civireport
WHERE {$logTypeTableClause}
-GROUP BY log_civicrm_entity_log_date, log_civicrm_entity_log_type_label, log_civicrm_entity_log_conn_id, log_civicrm_entity_log_user_id, log_civicrm_entity_altered_contact_id
+GROUP BY log_civicrm_entity_log_date, log_civicrm_entity_log_type_label, log_civicrm_entity_log_conn_id, log_civicrm_entity_log_user_id, log_civicrm_entity_altered_contact_id, log_civicrm_entity_log_grouping
ORDER BY log_civicrm_entity_log_date DESC {$this->_limit}";
$sql = str_replace('modified_contact_civireport.display_name', 'entity_log_civireport.altered_contact', $sql);
$sql = str_replace('modified_contact_civireport.id', 'entity_log_civireport.altered_contact_id', $sql);
'no_display' => TRUE,
'required' => TRUE,
),
+ 'log_grouping' => array(
+ 'required' => TRUE,
+ 'title' => ts('Extra information to control grouping'),
+ 'no_display' => TRUE,
+ ),
'log_action' => array(
'default' => TRUE,
'title' => ts('Action'),
$newRows = array();
foreach ($rows as $key => &$row) {
+ $isMerge = 0;
$baseQueryCriteria = "reset=1&log_conn_id={$row['log_civicrm_entity_log_conn_id']}";
if (!CRM_Logging_Differ::checkLogCanBeUsedWithNoLogDate($row['log_civicrm_entity_log_date'])) {
$baseQueryCriteria .= '&log_date=' . CRM_Utils_Date::isoToMysql($row['log_civicrm_entity_log_date']);
if ($entity) {
$row['log_civicrm_entity_altered_contact'] = $row['log_civicrm_entity_altered_contact'] . " [{$entity}]";
}
+ if ($entity == 'Contact Merged') {
+ $isMerge = 1;
+ }
+
}
$row['altered_by_contact_display_name_link'] = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $row['log_civicrm_entity_log_user_id']);
$row['altered_by_contact_display_name_hover'] = ts("Go to contact summary");
$key = $date . '_' .
$row['log_civicrm_entity_log_type'] . '_' .
+ // This ensures merge activities are not 'lost' by aggregation.
+ // I would prefer not to lose other entities either but it's a balancing act as
+ // described in https://issues.civicrm.org/jira/browse/CRM-12867 so adding this criteria
+ // while hackish saves us from figuring out if the original decision is still good.
+ $isMerge .
$row['log_civicrm_entity_log_conn_id'] . '_' .
$row['log_civicrm_entity_log_user_id'] . '_' .
$row['log_civicrm_entity_altered_contact_id'];
ON (fk_table.{$detail['fk']} = modified_contact_civireport.id {$clause})";
}
+ if (!empty($detail['extra_joins'])) {
+ $joinClause .= "
+INNER JOIN `{$this->loggingDB}`.{$detail['extra_joins']['table']} extra_table ON {$detail['extra_joins']['join']}";
+ }
+
$this->_from = "
FROM `{$this->loggingDB}`.$tableName entity_log_civireport
{$joinClause}