Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#183 Convert Logging report summary report to using CRM_Utils… #15825

Merged
merged 1 commit into from
Nov 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions CRM/Logging/ReportSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,9 @@ protected function buildTemporaryTables() {
}

// 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);
unset($this->_params['log_type_value']);
Expand All @@ -383,7 +383,7 @@ protected function buildTemporaryTables() {
$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();
Expand All @@ -395,7 +395,7 @@ protected function buildTemporaryTables() {

// 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 = [];
Expand All @@ -412,11 +412,11 @@ protected function buildTemporaryTables() {
}
}

$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);
}
Expand Down Expand Up @@ -448,7 +448,7 @@ public function buildQuery($applyLimit = TRUE) {
$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}
Expand All @@ -471,7 +471,7 @@ public function buildQuery($applyLimit = TRUE) {
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();
}

}