Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#183 Use Standard CRM_Utils_SQL_TempTable builder to create temporary tabl… #15792

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions CRM/Campaign/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,17 +502,10 @@ public static function voterClause($params) {
$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;
Expand Down
13 changes: 3 additions & 10 deletions CRM/Campaign/Form/Task/Interview.php
Original file line number Diff line number Diff line change
Expand Up @@ -591,16 +591,9 @@ public function filterVoterIds() {
$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 {
Expand Down
12 changes: 6 additions & 6 deletions CRM/Upgrade/Incremental/php/FourThree.php
Original file line number Diff line number Diff line change
Expand Up @@ -555,26 +555,26 @@ public function createFinancialRecords() {
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,
Expand Down Expand Up @@ -603,7 +603,7 @@ public function createFinancialRecords() {
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);";
Expand Down
39 changes: 39 additions & 0 deletions tests/phpunit/CRM/Campaign/BAO/QueryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
* Test APIv3 civicrm_contribute_* functions
*
* @package CiviCRM_APIv3
* @subpackage API_Contribution
* @group headless
*/
class CRM_Campaign_BAO_QueryTest extends CiviUnitTestCase {

public function testCampaignVoterClause() {
$loggedInContact = $this->createLoggedInUser();
$contact = $this->individualCreate();
$activityType = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'survey');
$surveyParams = [
'title' => 'Test Survey',
'activity_type_id' => $activityType,
'created_id' => $loggedInContact,
];
$survery = CRM_Campaign_BAO_Survey::create($surveyParams);
$voterClauseParams = [
'campaign_search_voter_for' => 'reserve',
'campaign_survey_id' => $survery->id,
'survey_interviewer_id' => $loggedInContact,
];
CRM_Campaign_BAO_Query::voterClause($voterClauseParams);
}

}