CRM-18214 Add link to detail report for contact merge activities, with oid if applicable
authoreileen <emcnaughton@wikimedia.org>
Thu, 7 Apr 2016 04:38:18 +0000 (16:38 +1200)
committerEileen <eileen@fuzion.co.nz>
Sat, 23 Apr 2016 03:51:15 +0000 (03:51 +0000)
After merging all my other changes the only thing needed for the dedupe merge report was it to be linked from the summary report and
to redirect after merge to the comparison of the 2 contacts, covered in this commit

CRM/Logging/ReportDetail.php
CRM/Report/Form/Contact/LoggingSummary.php

index 2e680da42cc09dde87a49271f6f309456bec7b0d..afefe3926cb6f8a8c36588a4547d4ba4766dfe10 100644 (file)
  */
 class CRM_Logging_ReportDetail extends CRM_Report_Form {
   protected $cid;
+
+  /**
+   * Other contact ID.
+   *
+   * This would be set if we are viewing a merge of 2 contacts.
+   *
+   * @var int
+   */
+  protected $oid;
   protected $db;
   protected $log_conn_id;
   protected $log_date;
@@ -122,8 +131,10 @@ class CRM_Logging_ReportDetail extends CRM_Report_Form {
   }
 
   /**
-   * @param $sql
-   * @param $rows
+   * Build rows from query.
+   *
+   * @param string $sql
+   * @param array $rows
    */
   public function buildRows($sql, &$rows) {
     // safeguard for when there aren’t any log entries yet
@@ -248,6 +259,9 @@ class CRM_Logging_ReportDetail extends CRM_Report_Form {
     $this->assign('log_date', CRM_Utils_Date::mysqlToIso($this->log_date));
 
     $q = "reset=1&log_conn_id={$this->log_conn_id}&log_date={$this->log_date}";
+    if ($this->oid) {
+      $q .= '&oid=' . $this->oid;
+    }
     $this->assign('revertURL', CRM_Report_Utils_Report::getNextUrl($this->detail, "$q&revert=1", FALSE, TRUE));
     $this->assign('revertConfirm', ts('Are you sure you want to revert all changes?'));
   }
@@ -262,10 +276,8 @@ class CRM_Logging_ReportDetail extends CRM_Report_Form {
 
   /**
    * Calculate all the contact related diffs for the change.
-   *
-   * @return array
    */
-  protected function calculateContactDiffs(){
+  protected function calculateContactDiffs() {
     $this->diffs = $this->getAllContactChangesForConnection();
   }
 
@@ -318,7 +330,18 @@ class CRM_Logging_ReportDetail extends CRM_Report_Form {
     $reverter->revert();
     CRM_Core_Session::setStatus(ts('The changes have been reverted.'), ts('Reverted'), 'success');
     if ($this->cid) {
-      CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view', "reset=1&selectedChild=log&cid={$this->cid}", FALSE, NULL, FALSE));
+      if ($this->oid) {
+        CRM_Utils_System::redirect(CRM_Utils_System::url(
+          'civicrm/contact/merge',
+          "reset=1&cid={$this->cid}&oid={$this->oid}",
+          FALSE,
+          NULL,
+          FALSE)
+        );
+      }
+      else {
+        CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view', "reset=1&selectedChild=log&cid={$this->cid}", FALSE, NULL, FALSE));
+      }
     }
     else {
       CRM_Utils_System::redirect(CRM_Report_Utils_Report::getNextUrl($this->summary, 'reset=1', FALSE, TRUE));
index 17c0b3f832ac4bf7c247c20658a7fd83613b18d3..d9e2dda0321e650ebb939fe87b67ca45672ecebc 100644 (file)
@@ -203,6 +203,17 @@ class CRM_Report_Form_Contact_LoggingSummary extends CRM_Logging_ReportSummary {
           $row['log_civicrm_entity_altered_contact'] = $row['log_civicrm_entity_altered_contact'] . " [{$entity}]";
         }
         if ($entity == 'Contact Merged') {
+          $deletedID = CRM_Core_DAO::singleValueQuery('
+            SELECT GROUP_CONCAT(contact_id) FROM civicrm_activity_contact ac
+            INNER JOIN civicrm_activity a
+            ON a.id = ac.activity_id AND a.parent_id = ' . $row['log_civicrm_entity_id'] . ' AND ac.record_type_id =
+            ' . CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_ActivityContact', 'record_type_id', 'Activity Targets')
+          );
+          if ($deletedID && !stristr($deletedID, ',')) {
+            $baseQueryCriteria .= '&oid=' . $deletedID;
+          }
+          $row['log_civicrm_entity_log_action'] = ts('Contact Merge');
+          $row = $this->addDetailReportLinksToRow($baseQueryCriteria, $row);
           $isMerge = 1;
         }