CRM-18193 do not require log_date
authoreileen <emcnaughton@wikimedia.org>
Wed, 6 Apr 2016 23:18:36 +0000 (11:18 +1200)
committerEileen <eileen@fuzion.co.nz>
Sat, 23 Apr 2016 03:51:13 +0000 (03:51 +0000)
Log_date should be an optional report parameter reflecting the changes in CRM-18193 to make the connection_id unique

CRM/Logging/Differ.php
CRM/Logging/ReportDetail.php

index 923629a809c6f8f1d0dcea2640fda14d94329e33..06a87b3b37ea703528b4ee1e83d05154e75cbac1 100644 (file)
@@ -269,11 +269,16 @@ WHERE lt.log_conn_id = %1
   }
 
   /**
-   * @param $table
+   * Get the titles & metadata option values for the table.
+   *
+   * For custom fields the titles may change so we use the ones as at the reference date.
+   *
+   * @param string $table
+   * @param string $referenceDate
    *
    * @return array
    */
-  public function titlesAndValuesForTable($table) {
+  public function titlesAndValuesForTable($table, $referenceDate) {
     // static caches for subsequent calls with the same $table
     static $titles = array();
     static $values = array();
@@ -325,7 +330,7 @@ WHERE lt.log_conn_id = %1
         }
       }
       elseif (substr($table, 0, 14) == 'civicrm_value_') {
-        list($titles[$table], $values[$table]) = $this->titlesAndValuesForCustomDataTable($table);
+        list($titles[$table], $values[$table]) = $this->titlesAndValuesForCustomDataTable($table, $referenceDate);
       }
       else {
         $titles[$table] = $values[$table] = array();
@@ -348,17 +353,20 @@ WHERE lt.log_conn_id = %1
   }
 
   /**
-   * @param $table
+   * Get the field titles & option group values for the custom table as at the reference date.
+   *
+   * @param string $table
+   * @param string $referenceDate
    *
    * @return array
    */
-  private function titlesAndValuesForCustomDataTable($table) {
+  private function titlesAndValuesForCustomDataTable($table, $referenceDate) {
     $titles = array();
     $values = array();
 
     $params = array(
       1 => array($this->log_conn_id, 'String'),
-      2 => array($this->log_date, 'String'),
+      2 => array($referenceDate, 'String'),
       3 => array($table, 'String'),
     );
 
index b30d7065f032b78fd30ca5e7642562f3312bb020..2e680da42cc09dde87a49271f6f309456bec7b0d 100644 (file)
@@ -127,7 +127,7 @@ class CRM_Logging_ReportDetail extends CRM_Report_Form {
    */
   public function buildRows($sql, &$rows) {
     // safeguard for when there aren’t any log entries yet
-    if (!$this->log_conn_id or !$this->log_date) {
+    if (!$this->log_conn_id && !$this->log_date) {
       return;
     }
     $this->getDiffs();
@@ -177,7 +177,7 @@ class CRM_Logging_ReportDetail extends CRM_Report_Form {
     foreach ($this->diffs as $diff) {
       $table = $diff['table'];
       if (empty($metadata[$table])) {
-        list($metadata[$table]['titles'], $metadata[$table]['values']) = $this->differ->titlesAndValuesForTable($table);
+        list($metadata[$table]['titles'], $metadata[$table]['values']) = $this->differ->titlesAndValuesForTable($table, $diff['log_date']);
       }
       $values = CRM_Utils_Array::value('values', $metadata[$diff['table']], array());
       $titles = $metadata[$diff['table']]['titles'];