Use TempTable methods.
authormark burdett <mfburdett@gmail.com>
Thu, 14 Mar 2019 23:42:46 +0000 (16:42 -0700)
committereileen <emcnaughton@wikimedia.org>
Sun, 17 Mar 2019 22:25:45 +0000 (11:25 +1300)
CRM/Report/Form/Contribute/Detail.php
tests/phpunit/CRM/Report/Form/ActivityTest.php
tests/phpunit/CRM/Report/Form/Contribute/DetailTest.php
tests/phpunit/CRM/Report/Form/TestCaseTest.php

index eccb17c26b43826d324703cda16632e5836c4a3f..9796c52599b87821fac7eb7a5335044158c08440 100644 (file)
@@ -491,7 +491,7 @@ GROUP BY {$this->_aliases['civicrm_contribution']}.currency";
   public function buildQuery($applyLimit = FALSE) {
     if ($this->isTempTableBuilt) {
       $this->limit();
-      return "SELECT SQL_CALC_FOUND_ROWS * FROM civireport_contribution_detail_temp3 $this->_orderBy $this->_limit";
+      return "SELECT SQL_CALC_FOUND_ROWS * FROM {$this->temporaryTables['civireport_contribution_detail_temp3']['name']} $this->_orderBy $this->_limit";
     }
     return parent::buildQuery($applyLimit);
   }
@@ -544,9 +544,7 @@ GROUP BY {$this->_aliases['civicrm_contribution']}.currency";
     // we inner join with temp1 to restrict soft contributions to those in temp1 table.
     // no group by here as we want to display as many soft credit rows as actually exist.
     $sql = "{$select} {$this->_from} {$this->_where} $this->_groupBy";
-    $tempQuery = "CREATE TEMPORARY TABLE civireport_contribution_detail_temp2 {$this->_databaseAttributes} AS {$sql}";
-    $this->executeReportQuery($tempQuery);
-    $this->temporaryTables['civireport_contribution_detail_temp2'] = ['name' => 'civireport_contribution_detail_temp2', 'temporary' => TRUE];
+    $this->createTemporaryTable('civireport_contribution_detail_temp2', $sql);
 
     if (CRM_Utils_Array::value('contribution_or_soft_value', $this->_params) ==
       'soft_credits_only'
@@ -568,24 +566,23 @@ GROUP BY {$this->_aliases['civicrm_contribution']}.currency";
     // 3. Decide where to populate temp3 table from
     if ($this->isContributionBaseMode
     ) {
-      $this->executeReportQuery(
-        "CREATE TEMPORARY TABLE civireport_contribution_detail_temp3 {$this->_databaseAttributes} AS (SELECT * FROM {$this->temporaryTables['civireport_contribution_detail_temp1']['name']})"
+      $this->createTemporaryTable('civireport_contribution_detail_temp3',
+        "(SELECT * FROM {$this->temporaryTables['civireport_contribution_detail_temp1']['name']})"
       );
     }
     elseif (CRM_Utils_Array::value('contribution_or_soft_value', $this->_params) ==
       'soft_credits_only'
     ) {
-      $this->executeReportQuery(
-        "CREATE TEMPORARY TABLE civireport_contribution_detail_temp3 {$this->_databaseAttributes} AS (SELECT * FROM civireport_contribution_detail_temp2)"
+      $this->createTemporaryTable('civireport_contribution_detail_temp3',
+        "(SELECT * FROM {$this->temporaryTables['civireport_contribution_detail_temp2']['name']})"
       );
     }
     else {
-      $this->executeReportQuery("CREATE TEMPORARY TABLE civireport_contribution_detail_temp3 {$this->_databaseAttributes}
+      $this->createTemporaryTable('civireport_contribution_detail_temp3', "
 (SELECT * FROM {$this->temporaryTables['civireport_contribution_detail_temp1']['name']})
 UNION ALL
-(SELECT * FROM civireport_contribution_detail_temp2)");
+(SELECT * FROM {$this->temporaryTables['civireport_contribution_detail_temp2']['name']})");
     }
-    $this->temporaryTables['civireport_contribution_detail_temp3'] = ['name' => 'civireport_contribution_detail_temp3', 'temporary' => TRUE];
     $this->isTempTableBuilt = TRUE;
   }
 
@@ -730,7 +727,7 @@ UNION ALL
       ) {
         $query = "
 SELECT civicrm_contact_id, civicrm_contact_sort_name, civicrm_contribution_total_amount_sum, civicrm_contribution_currency
-FROM   civireport_contribution_detail_temp2
+FROM   {$this->temporaryTables['civireport_contribution_detail_temp2']['name']}
 WHERE  civicrm_contribution_contribution_id={$row['civicrm_contribution_contribution_id']}";
         $dao = CRM_Core_DAO::executeQuery($query);
         $string = '';
@@ -834,7 +831,7 @@ WHERE  civicrm_contribution_contribution_id={$row['civicrm_contribution_contribu
       }
 
       $query = $this->_select .
-        "$addtotals, count(*) as ct from civireport_contribution_detail_temp3 group by " .
+        "$addtotals, count(*) as ct from {$this->temporaryTables['civireport_contribution_detail_temp3']['name']} group by " .
         implode(", ", $sectionAliases);
       // initialize array of total counts
       $sumcontribs = $totals = array();
index 582dd6a4ce9176d9ec577fde11ae3289b61e11e1..d7001ea91aeba8f8a510bc5d13a7e051901560be 100644 (file)
@@ -46,9 +46,6 @@ class CRM_Report_Form_ActivityTest extends CiviReportTestCase {
 
   public function tearDown() {
     parent::tearDown();
-    CRM_Core_DAO::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_contribution_detail_temp1');
-    CRM_Core_DAO::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_contribution_detail_temp2');
-    CRM_Core_DAO::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_contribution_detail_temp3');
     CRM_Core_DAO::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_activity_temp_target');
   }
 
index af89473113a8071e68c3dd6cbf53742729544e03..835f37462d106b57b846bda6f66d2974d948aca4 100644 (file)
@@ -70,13 +70,6 @@ class CRM_Report_Form_Contribute_DetailTest extends CiviReportTestCase {
     $this->quickCleanup($this->_tablesToTruncate);
   }
 
-  public function tearDown() {
-    parent::tearDown();
-    CRM_Core_DAO::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_contribution_detail_temp1');
-    CRM_Core_DAO::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_contribution_detail_temp2');
-    CRM_Core_DAO::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_contribution_detail_temp3');
-  }
-
   /**
    * @dataProvider dataProvider
    * @param $reportClass
index 7d144fb7c6dbb7a3e8ccc64fd4940e20ba2987c8..0f1471084b17b2f8a052360e6dcd8cd3ca1d85ce 100644 (file)
@@ -134,13 +134,6 @@ class CRM_Report_Form_TestCaseTest extends CiviReportTestCase {
     $this->quickCleanup($this->_tablesToTruncate);
   }
 
-  public function tearDown() {
-    parent::tearDown();
-    CRM_Core_DAO::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_contribution_detail_temp1');
-    CRM_Core_DAO::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_contribution_detail_temp2');
-    CRM_Core_DAO::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_contribution_detail_temp3');
-  }
-
   /**
    * @dataProvider dataProvider
    * @param $reportClass