From 0b4c85c397e0d88819a63c7e27fe5e974bb249b6 Mon Sep 17 00:00:00 2001 From: Deepak Srivastava Date: Tue, 5 Mar 2013 18:17:02 +0530 Subject: [PATCH] CRM-11968 : fixed no diff to display problem for multiple targets --- CRM/Logging/Differ.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/CRM/Logging/Differ.php b/CRM/Logging/Differ.php index 8a1de3d3c7..e93c4133d5 100644 --- a/CRM/Logging/Differ.php +++ b/CRM/Logging/Differ.php @@ -65,7 +65,7 @@ class CRM_Logging_Differ { 2 => array($this->log_date, 'String'), ); - $contactIdClause = ''; + $contactIdClause = $join = ''; if ( $contactID ) { $params[3] = array($contactID, 'Integer'); switch ($table) { @@ -82,10 +82,11 @@ class CRM_Logging_Differ { $contactIdClause = "AND (contact_id_a = %3 OR contact_id_b = %3)"; break; case 'civicrm_activity': - $contactIdClause = " -AND (id = (select activity_id FROM civicrm_activity_target WHERE target_contact_id = %3 LIMIT 1) OR - id = (select activity_id FROM civicrm_activity_assignment WHERE assignee_contact_id = %3 LIMIT 1) OR - source_contact_id = %3)"; + $join = " +LEFT JOIN civicrm_activity_target at ON at.activity_id = lt.id AND at.target_contact_id = %3 +LEFT JOIN civicrm_activity_assignment aa ON aa.activity_id = lt.id AND aa.assignee_contact_id = %3 +LEFT JOIN civicrm_activity source ON source.id = lt.id AND source.source_contact_id = %3"; + $contactIdClause = "AND (at.id IS NOT NULL OR aa.id IS NOT NULL OR source.id IS NOT NULL)"; break; case 'civicrm_case': $contactIdClause = "AND id = (select case_id FROM civicrm_case_contact WHERE contact_id = %3 LIMIT 1)"; @@ -99,8 +100,12 @@ AND (id = (select activity_id FROM civicrm_activity_target WHERE target_contact_ } // find ids in this table that were affected in the given connection (based on connection id and a ±10 s time period around the date) - $sql = "SELECT DISTINCT id FROM `{$this->db}`.`log_$table` WHERE log_conn_id = %1 AND log_date BETWEEN DATE_SUB(%2, INTERVAL {$this->interval}) AND DATE_ADD(%2, INTERVAL {$this->interval}) {$contactIdClause}"; - + $sql = " +SELECT DISTINCT lt.id FROM `{$this->db}`.`log_$table` lt +{$join} +WHERE log_conn_id = %1 AND + log_date BETWEEN DATE_SUB(%2, INTERVAL {$this->interval}) AND DATE_ADD(%2, INTERVAL {$this->interval}) + {$contactIdClause}"; $dao = CRM_Core_DAO::executeQuery($sql, $params); while ($dao->fetch()) { $diffs = array_merge($diffs, $this->diffsInTableForId($table, $dao->id)); -- 2.25.1