Use Standard CRM_Utils_SQL_TempTable builder to create temporary table in Campaign...
authorSeamus Lee <seamuslee001@gmail.com>
Sat, 9 Nov 2019 22:23:20 +0000 (09:23 +1100)
committerSeamus Lee <seamuslee001@gmail.com>
Thu, 21 Nov 2019 05:37:51 +0000 (16:37 +1100)
CRM/Campaign/BAO/Query.php
CRM/Campaign/Form/Task/Interview.php
CRM/Upgrade/Incremental/php/FourThree.php

index 76e73063652bec62f9e709132d74737467185cf3..02e251f760f50b7b516d4201c147d1f16a1cc3f8 100644 (file)
@@ -502,17 +502,10 @@ INNER JOIN  civicrm_custom_group grp on fld.custom_group_id = grp.id
         $voterIdCount = count($voterIds);
 
         //create temporary table to store voter ids.
-        $tempTableName = CRM_Core_DAO::createTempTableName('civicrm_survey_respondent');
+        $tempTable = CRM_Utils_SQL_TempTable::build();
+        $tempTableName = $tempTable->getName();
         CRM_Core_DAO::executeQuery("DROP TEMPORARY TABLE IF EXISTS {$tempTableName}");
-
-        $query = "
-     CREATE TEMPORARY TABLE {$tempTableName} (
-            id int unsigned NOT NULL AUTO_INCREMENT,
-            survey_contact_id int unsigned NOT NULL,
-  PRIMARY KEY ( id )
-);
-";
-        CRM_Core_DAO::executeQuery($query);
+        $tempTable->createWithColumns('id int unsigned NOT NULL AUTO_INCREMENT, survey_contact_id int unsigned NOT NULL, PRIMARY KEY ( id )')
 
         $batch = 100;
         $insertedCount = 0;
index 72f39d6eaf4ba7f2d357834dc7bc5bffb1ed93da..fb178f363601e763531e3fbe4faae25063a0a147 100644 (file)
@@ -591,16 +591,9 @@ WHERE {$clause}
         $voterIdCount = count($this->_contactIds);
 
         //create temporary table to store voter ids.
-        $tempTableName = CRM_Core_DAO::createTempTableName('civicrm_survey_respondent');
-        CRM_Core_DAO::executeQuery("DROP TEMPORARY TABLE IF EXISTS {$tempTableName}");
-        $query = "
-     CREATE TEMPORARY TABLE {$tempTableName} (
-            id int unsigned NOT NULL AUTO_INCREMENT,
-            survey_contact_id int unsigned NOT NULL,
-  PRIMARY KEY ( id )
-);
-";
-        CRM_Core_DAO::executeQuery($query);
+        $tempTableName = CRM_Utils_SQL_TempTable::build()
+          ->createWithColumns('id int unsigned NOT NULL AUTO_INCREMENT, survey_contact_id int unsigned NOT NULL, PRIMARY KEY ( id )')
+          ->getName();
         $batch = 100;
         $insertedCount = 0;
         do {
index c5e718e46b59180ba52d864b1b84b621dfd5b766..9883c425a38002f766c2c00e7e25529bb5b10ef0 100644 (file)
@@ -555,26 +555,26 @@ AND   con.contribution_status_id = {$pendingStatus}
     CRM_Core_DAO::executeQuery($sql);
 
     //create a temp table to hold financial account id related to payment instruments
-    $tempTableName1 = CRM_Core_DAO::createTempTableName();
+    $tempTable1 = CRM_Utils_SQL_TempTable::build()->setCategory('upgrade43')->setDurable();
 
     $sql = "
-CREATE TEMPORARY TABLE {$tempTableName1}
 SELECT     ceft.financial_account_id financial_account_id, cov.value as instrument_id
 FROM       civicrm_entity_financial_account ceft
 INNER JOIN civicrm_option_value cov ON cov.id = ceft.entity_id AND ceft.entity_table = 'civicrm_option_value'
 INNER JOIN civicrm_option_group cog ON cog.id = cov.option_group_id
 WHERE      cog.name = 'payment_instrument'
 ";
-    CRM_Core_DAO::executeQuery($sql);
+    $tempTable1->createWithQuery($sql);
+    $tempTableName1 = $tempTable1->getName();
 
     //CRM-12141
     $sql = "ALTER TABLE {$tempTableName1} ADD INDEX index_instrument_id (instrument_id(200));";
     CRM_Core_DAO::executeQuery($sql);
 
     //create temp table to process completed / cancelled contribution
-    $tempTableName2 = CRM_Core_DAO::createTempTableName();
+    $tempTable2 = CRM_Utils_SQL_TempTable::build()->setCategory('upgrade43')->setDurable();
+    $tempTableName2 = $tempTable2->getName();
     $sql = "
-CREATE TEMPORARY TABLE {$tempTableName2}
 SELECT con.id as contribution_id, con.payment_instrument_id,
        IF(con.currency IN ('{$validCurrencyCodes}'), con.currency, '{$defaultCurrency}') as currency,
        con.total_amount, con.net_amount, con.fee_amount, con.trxn_id, con.contribution_status_id,
@@ -603,7 +603,7 @@ LEFT JOIN {$tempTableName1} tpi
        ON con.payment_instrument_id = tpi.instrument_id
 WHERE     con.contribution_status_id IN ({$completedStatus}, {$cancelledStatus})
 ";
-    CRM_Core_DAO::executeQuery($sql);
+    $tempTable2->createWithQuery($sql);
 
     // CRM-12141
     $sql = "ALTER TABLE {$tempTableName2} ADD INDEX index_action (action);";