Merge pull request #22652 from civicrm/5.46
[civicrm-core.git] / CRM / Logging / ReportSummary.php
index db7e09a13c9f9c171aa82a44e4f43bb1c550a4ec..5ecdcac11bebff0136b4ed60fae0b8946134e07e 100644 (file)
  */
 
 /**
- *
- * @package CRM
- * @copyright CiviCRM LLC https://civicrm.org/licensing
- * $Id$
+ * Class CRM_Logging_ReportSummary
  */
 class CRM_Logging_ReportSummary extends CRM_Report_Form {
   protected $cid;
@@ -280,7 +277,7 @@ WHERE  log_date <= %1 AND id = %2 ORDER BY log_date DESC LIMIT 1";
         if (array_key_exists('options', $this->_logTables[$entity]['bracket_info']) &&
           $entityID
         ) {
-          return CRM_Utils_Array::value($entityID, $this->_logTables[$entity]['bracket_info']['options']);
+          return $this->_logTables[$entity]['bracket_info']['options'][$entityID] ?? NULL;
         }
       }
     }
@@ -338,11 +335,11 @@ WHERE  log_date <= %1 AND id = %2 ORDER BY log_date DESC LIMIT 1";
     }
 
     // temp table to hold all altered contact-ids
-    $sql = "CREATE TEMPORARY TABLE civicrm_temp_civireport_logsummary ( {$tempColumns} ) ENGINE=HEAP";
-    CRM_Core_DAO::executeQuery($sql);
-    $this->addToDeveloperTab($sql);
+    $this->temporaryTable = CRM_Utils_SQL_TempTable::build()->setCategory('logsummary')->setMemory()->createwithColumns($tempColumns);
+    $this->addToDeveloperTab($this->temporaryTable->getCreateSql());
+    $this->temporaryTableName = $this->temporaryTable->getName();
 
-    $logTypes = CRM_Utils_Array::value('log_type_value', $this->_params);
+    $logTypes = $this->_params['log_type_value'] ?? NULL;
     unset($this->_params['log_type_value']);
     if (empty($logTypes)) {
       foreach (array_keys($this->_logTables) as $table) {
@@ -367,7 +364,7 @@ WHERE  log_date <= %1 AND id = %2 ORDER BY log_date DESC LIMIT 1";
         $this->currentLogTable = $entity;
         $sql = $this->buildQuery(FALSE);
         $sql = str_replace("entity_log_civireport.log_type as", "'{$entity}' as", $sql);
-        $sql = "INSERT IGNORE INTO civicrm_temp_civireport_logsummary {$sql}";
+        $sql = "INSERT IGNORE INTO {$this->temporaryTableName} {$sql}";
         CRM_Core_DAO::disableFullGroupByMode();
         CRM_Core_DAO::executeQuery($sql);
         CRM_Core_DAO::reenableFullGroupByMode();
@@ -379,7 +376,7 @@ WHERE  log_date <= %1 AND id = %2 ORDER BY log_date DESC LIMIT 1";
 
     // add computed log_type column so that we can do a group by after that, which will help
     // alterDisplay() counts sync with pager counts
-    $sql = "SELECT DISTINCT log_type FROM civicrm_temp_civireport_logsummary";
+    $sql = "SELECT DISTINCT log_type FROM {$this->temporaryTableName}";
     $dao = CRM_Core_DAO::executeQuery($sql);
     $this->addToDeveloperTab($sql);
     $replaceWith = [];
@@ -396,11 +393,11 @@ WHERE  log_date <= %1 AND id = %2 ORDER BY log_date DESC LIMIT 1";
       }
     }
 
-    $sql = "ALTER TABLE civicrm_temp_civireport_logsummary ADD COLUMN log_civicrm_entity_log_type_label varchar(64)";
+    $sql = "ALTER TABLE {$this->temporaryTableName} ADD COLUMN log_civicrm_entity_log_type_label varchar(64)";
     CRM_Core_DAO::executeQuery($sql);
     $this->addToDeveloperTab($sql);
     foreach ($replaceWith as $type => $in) {
-      $sql = "UPDATE civicrm_temp_civireport_logsummary SET log_civicrm_entity_log_type_label='{$type}', log_date=log_date WHERE log_type IN('$in')";
+      $sql = "UPDATE {$this->temporaryTableName} SET log_civicrm_entity_log_type_label='{$type}', log_date=log_date WHERE log_type IN('$in')";
       CRM_Core_DAO::executeQuery($sql);
       $this->addToDeveloperTab($sql);
     }
@@ -432,7 +429,7 @@ WHERE  log_date <= %1 AND id = %2 ORDER BY log_date DESC LIMIT 1";
     $this->limit();
     $this->orderBy();
     $sql = "{$this->_select}
-FROM civicrm_temp_civireport_logsummary entity_log_civireport
+FROM {$this->temporaryTableName} entity_log_civireport
 WHERE {$this->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, log_civicrm_entity_log_grouping
 {$this->_orderBy}
@@ -455,7 +452,7 @@ GROUP BY log_civicrm_entity_log_date, log_civicrm_entity_log_type_label, log_civ
   public function buildRows($sql, &$rows) {
     parent::buildRows($sql, $rows);
     // Clean up the temp table - mostly for the unit test.
-    CRM_Core_DAO::executeQuery('DROP TEMPORARY TABLE IF EXISTS civicrm_temp_civireport_logsummary');
+    $this->temporaryTable->drop();
   }
 
 }