From: Seamus Lee Date: Sat, 9 Nov 2019 22:23:20 +0000 (+1100) Subject: Use Standard CRM_Utils_SQL_TempTable builder to create temporary table in Campaign... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=6c0b6d2ac05f3931123d5b7aee8f9164eaa2ef3c;p=civicrm-core.git Use Standard CRM_Utils_SQL_TempTable builder to create temporary table in Campaign and upgrade --- diff --git a/CRM/Campaign/BAO/Query.php b/CRM/Campaign/BAO/Query.php index 76e7306365..02e251f760 100644 --- a/CRM/Campaign/BAO/Query.php +++ b/CRM/Campaign/BAO/Query.php @@ -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; diff --git a/CRM/Campaign/Form/Task/Interview.php b/CRM/Campaign/Form/Task/Interview.php index 72f39d6eaf..fb178f3636 100644 --- a/CRM/Campaign/Form/Task/Interview.php +++ b/CRM/Campaign/Form/Task/Interview.php @@ -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 { diff --git a/CRM/Upgrade/Incremental/php/FourThree.php b/CRM/Upgrade/Incremental/php/FourThree.php index c5e718e46b..9883c425a3 100644 --- a/CRM/Upgrade/Incremental/php/FourThree.php +++ b/CRM/Upgrade/Incremental/php/FourThree.php @@ -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);";