From f7e48badfcde6af82dd052062f4ce1f570f0fce8 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 14 Jun 2018 17:03:54 -0700 Subject: [PATCH] (dev/core#183) Change temp table naming for reports Testing notes - This is a pretty formulaic change. The main concern is some kind of typo or bad table name causing a hard-fail. To control that risk, we just run the code in a facile way: * Navigate to "Reports => Contributions => Lybunt" * Add a "Filter" by "Group" We do this procedure under a few circumstances: * With the original code * With a purposefully bad edit (provoking an expected error) * With the new code In this commit, we changed two lines, so we do the above once for each line. --- CRM/Core/Config.php | 2 ++ CRM/Report/Form.php | 2 +- CRM/Report/Form/Contribute/Lybunt.php | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CRM/Core/Config.php b/CRM/Core/Config.php index 03bf571444..196ad6f456 100644 --- a/CRM/Core/Config.php +++ b/CRM/Core/Config.php @@ -393,6 +393,8 @@ class CRM_Core_Config extends CRM_Core_Config_MagicMerge { OR TABLE_NAME LIKE 'civicrm_tmp_d%' ) "; + // NOTE: Cannot find use-cases where "civicrm_report_temp" would be durable. Could probably remove. + if ($timeInterval) { $query .= " AND CREATE_TIME < DATE_SUB(NOW(), INTERVAL {$timeInterval})"; } diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index dc599e03b2..e745e93f63 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -3689,7 +3689,7 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND WHERE smartgroup_contact.group_id IN ({$smartGroups}) "; } - $this->groupTempTable = 'civicrm_report_temp_group_' . date('Ymd_') . uniqid(); + $this->groupTempTable = CRM_Utils_SQL_TempTable::build()->setCategory('rptgrp')->setId(date('Ymd_') . uniqid())->getName(); $this->executeReportQuery(" CREATE TEMPORARY TABLE $this->groupTempTable $this->_databaseAttributes $query diff --git a/CRM/Report/Form/Contribute/Lybunt.php b/CRM/Report/Form/Contribute/Lybunt.php index 0fb7f093a5..e5aeb0fcba 100644 --- a/CRM/Report/Form/Contribute/Lybunt.php +++ b/CRM/Report/Form/Contribute/Lybunt.php @@ -567,7 +567,7 @@ class CRM_Report_Form_Contribute_Lybunt extends CRM_Report_Form { // @todo this acl has no test coverage and is very hard to test manually so could be fragile. $this->resetFormSqlAndWhereHavingClauses(); - $this->contactTempTable = 'civicrm_report_temp_lybunt_c_' . date('Ymd_') . uniqid(); + $this->contactTempTable = CRM_Utils_SQL_TempTable::build()->setCategory('rptlybunt')->setId(date('Ymd_') . uniqid())->getName(); $this->limit(); $getContacts = " CREATE TEMPORARY TABLE $this->contactTempTable {$this->_databaseAttributes} -- 2.25.1