dev/core#183 Finish converting contrib sybnt custom search to using tem table class
authorSeamus Lee <seamuslee001@gmail.com>
Mon, 11 Nov 2019 20:42:14 +0000 (07:42 +1100)
committerSeamus Lee <seamuslee001@gmail.com>
Wed, 13 Nov 2019 07:27:57 +0000 (18:27 +1100)
CRM/Contact/Form/Search/Custom/ContribSYBNT.php

index 42d085f1c5312f3fff7402b241e732453e7275cf..93cfb8a7ed2effa2f5c4b50beb106838833d1b24 100644 (file)
@@ -229,7 +229,7 @@ count(contrib_1.id) AS donation_count
       !empty($this->exclude_end_date) ||
       !empty($this->is_first_amount)
     ) {
-      $from .= " LEFT JOIN XG_CustomSearch_SYBNT xg ON xg.contact_id = contact_a.id ";
+      $from .= " LEFT JOIN {$this->_xgTableName} xg ON xg.contact_id = contact_a.id ";
     }
 
     return $from;
@@ -269,11 +269,11 @@ count(contrib_1.id) AS donation_count
     ) {
 
       // first create temp table to store contact ids
-      $sql = "DROP TEMPORARY TABLE IF EXISTS XG_CustomSearch_SYBNT";
-      CRM_Core_DAO::executeQuery($sql);
-
-      $sql = "CREATE TEMPORARY TABLE XG_CustomSearch_SYBNT ( contact_id int primary key) ENGINE=HEAP";
+      $this->_xgTable = CRM_Utils_SQL_TempTable::build()->setMemory();
+      $this->_xgTableName = $this->_xgTable->getName();
+      $sql = "DROP TEMPORARY TABLE IF EXISTS {$this->_xgTableName}";
       CRM_Core_DAO::executeQuery($sql);
+      $this->_xgTable->createWithColumns('contact_id int primary key');
 
       $excludeClauses = [];
       if ($this->exclude_start_date) {
@@ -306,7 +306,7 @@ count(contrib_1.id) AS donation_count
       if ($excludeClause || $havingClause) {
         // Run subquery
         $query = "
-REPLACE   INTO XG_CustomSearch_SYBNT
+REPLACE   INTO {$this->_xgTableName}
 SELECT   DISTINCT contact_id AS contact_id
 FROM     civicrm_contribution c
 WHERE    c.is_test = 0
@@ -321,7 +321,7 @@ GROUP BY c.contact_id
       // now ensure we dont consider donors that are not first time
       if ($this->is_first_amount) {
         $query = "
-REPLACE  INTO XG_CustomSearch_SYBNT
+REPLACE  INTO {$this->_xgTableName}
 SELECT   DISTINCT contact_id AS contact_id
 FROM     civicrm_contribution c
 WHERE    c.is_test = 0