From 9bf49a0eb89a840e122f7fdb288a93e4d49ac0d4 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 7 Apr 2016 16:29:02 +1200 Subject: [PATCH] CRM-18193 do not pass log_date_id to detail report if the log_conn_id is sufficient Prior to CRM-18193 the connection was estimated using the a log_date_range + log_conn_id. After CRM-18193 the connection_id is unique and the log_date is not required (and could make the result less accurate Change-Id: I72c8cf254720654003154702b45e7f0a0b8aabe5 --- CRM/Logging/Differ.php | 5 ++- CRM/Report/Form/Contact/LoggingSummary.php | 43 +++++++++++++++------- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/CRM/Logging/Differ.php b/CRM/Logging/Differ.php index 06a87b3b37..156fc6a70e 100644 --- a/CRM/Logging/Differ.php +++ b/CRM/Logging/Differ.php @@ -190,7 +190,7 @@ WHERE lt.log_conn_id = %1 $changedDAO = CRM_Core_DAO::executeQuery($changedSQL, $params); while ($changedDAO->fetch()) { - if (empty($this->log_date) && !$this->checkLogCanBeUsedWithNoLogDate($changedDAO->log_date)) { + if (empty($this->log_date) && !self::checkLogCanBeUsedWithNoLogDate($changedDAO->log_date)) { throw new CRM_Core_Exception('The connection date must be passed in to disambiguate this logging entry per CRM-18193'); } $changed = $changedDAO->toArray(); @@ -459,7 +459,8 @@ ORDER BY log_date * @return bool * @throws \CiviCRM_API3_Exception */ - protected function checkLogCanBeUsedWithNoLogDate($change_date) { + public static function checkLogCanBeUsedWithNoLogDate($change_date) { + if (civicrm_api3('Setting', 'getvalue', array('name' => 'logging_all_tables_uniquid', 'group' => 'CiviCRM Preferences'))) { return TRUE; }; diff --git a/CRM/Report/Form/Contact/LoggingSummary.php b/CRM/Report/Form/Contact/LoggingSummary.php index 2ee03a7831..238888874b 100644 --- a/CRM/Report/Form/Contact/LoggingSummary.php +++ b/CRM/Report/Form/Contact/LoggingSummary.php @@ -174,6 +174,13 @@ class CRM_Report_Form_Contact_LoggingSummary extends CRM_Logging_ReportSummary { $newRows = array(); foreach ($rows as $key => &$row) { + $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 ($this->cid) { + $baseQueryCriteria .= '&cid=' . $this->cid; + } if (!isset($isDeleted[$row['log_civicrm_entity_altered_contact_id']])) { $isDeleted[$row['log_civicrm_entity_altered_contact_id']] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $row['log_civicrm_entity_altered_contact_id'], 'is_deleted') !== '0'; @@ -198,7 +205,7 @@ class CRM_Report_Form_Contact_LoggingSummary extends CRM_Logging_ReportSummary { } if ('Contact' == CRM_Utils_Array::value('log_type', $this->_logTables[$row['log_civicrm_entity_log_type']]) && - CRM_Utils_Array::value('log_civicrm_entity_log_action', $row) == 'Insert' + CRM_Utils_Array::value('log_civicrm_entity_log_action', $row) == ts('Insert') ) { $row['log_civicrm_entity_log_action'] = ts('Update'); } @@ -216,18 +223,7 @@ class CRM_Report_Form_Contact_LoggingSummary extends CRM_Logging_ReportSummary { $date = CRM_Utils_Date::isoToMysql($row['log_civicrm_entity_log_date']); if ('Update' == CRM_Utils_Array::value('log_civicrm_entity_log_action', $row)) { - $q = "reset=1&log_conn_id={$row['log_civicrm_entity_log_conn_id']}&log_date=" . $date; - if ($this->cid) { - $q .= '&cid=' . $this->cid; - } - $q .= (!empty($row['log_civicrm_entity_altered_contact'])) ? '&alteredName=' . $row['log_civicrm_entity_altered_contact'] : ''; - $q .= (!empty($row['altered_by_contact_display_name'])) ? '&alteredBy=' . $row['altered_by_contact_display_name'] : ''; - $q .= (!empty($row['log_civicrm_entity_log_user_id'])) ? '&alteredById=' . $row['log_civicrm_entity_log_user_id'] : ''; - - $url1 = CRM_Report_Utils_Report::getNextUrl('logging/contact/detail', "{$q}&snippet=4§ion=2&layout=overlay", FALSE, TRUE); - $url2 = CRM_Report_Utils_Report::getNextUrl('logging/contact/detail', "{$q}§ion=2", FALSE, TRUE); - $hoverTitle = ts('View details for this update'); - $row['log_civicrm_entity_log_action'] = " " . ts('Update') . ''; + $row = $this->addDetailReportLinksToRow($baseQueryCriteria, $row); } $key = $date . '_' . @@ -276,4 +272,25 @@ LEFT JOIN civicrm_contact altered_by_contact_civireport ON (entity_log_civireport.log_user_id = altered_by_contact_civireport.id)"; } + /** + * Add links & hovers to the detailed report. + * + * @param $baseQueryCriteria + * @param $row + * + * @return mixed + */ + protected function addDetailReportLinksToRow($baseQueryCriteria, $row) { + $q = $baseQueryCriteria; + $q .= (!empty($row['log_civicrm_entity_altered_contact'])) ? '&alteredName=' . $row['log_civicrm_entity_altered_contact'] : ''; + $q .= (!empty($row['altered_by_contact_display_name'])) ? '&alteredBy=' . $row['altered_by_contact_display_name'] : ''; + $q .= (!empty($row['log_civicrm_entity_log_user_id'])) ? '&alteredById=' . $row['log_civicrm_entity_log_user_id'] : ''; + + $url1 = CRM_Report_Utils_Report::getNextUrl('logging/contact/detail', "{$q}&snippet=4§ion=2&layout=overlay", FALSE, TRUE); + $url2 = CRM_Report_Utils_Report::getNextUrl('logging/contact/detail', "{$q}§ion=2", FALSE, TRUE); + $hoverTitle = ts('View details for this update'); + $row['log_civicrm_entity_log_action'] = " " . $row['log_civicrm_entity_log_action'] . ''; + return $row; + } + } -- 2.25.1