From 47c6f463edb9ec11601955d1e035ccfd301a4642 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sat, 28 Aug 2021 12:21:34 +1200 Subject: [PATCH] dev/core#2786 Ensure non-English installs have a default financial type for membership default price set --- CRM/Upgrade/Incremental/php/FiveFortyOne.php | 36 ++++++++++++++++++++ xml/templates/civicrm_data.tpl | 3 +- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/CRM/Upgrade/Incremental/php/FiveFortyOne.php b/CRM/Upgrade/Incremental/php/FiveFortyOne.php index 027f0be9c1..cab70b9c26 100644 --- a/CRM/Upgrade/Incremental/php/FiveFortyOne.php +++ b/CRM/Upgrade/Incremental/php/FiveFortyOne.php @@ -85,6 +85,42 @@ class CRM_Upgrade_Incremental_php_FiveFortyOne extends CRM_Upgrade_Incremental_B ); } + /** + * Upgrade function. + * + * @param string $rev + */ + public function upgrade_5_41_beta1($rev) { + $this->addTask('Ensure non-English installs have a default financial type for the membership price set.', + 'ensureDefaultMembershipFinancialType'); + } + + public static function ensureDefaultMembershipFinancialType(): bool { + $membershipPriceSet = CRM_Core_DAO::executeQuery( + 'SELECT id, financial_type_id FROM civicrm_price_set WHERE name = "default_membership_type_amount"' + ); + $membershipPriceSet->fetch(); + if (!is_numeric($membershipPriceSet->financial_type_id)) { + $membershipFinancialTypeID = CRM_Core_DAO::singleValueQuery(' + SELECT id FROM civicrm_financial_type + WHERE name = "Member Dues" + OR name = %1', [1 => [ts('Member Dues'), 'String']] + ); + if (!$membershipFinancialTypeID) { + // This should be unreachable - but something is better than nothing + // if we get to this point & 2 will be correct on 99.9% of installs. + $membershipFinancialTypeID = 2; + } + CRM_Core_DAO::executeQuery(" + UPDATE civicrm_price_set + SET financial_type_id = $membershipFinancialTypeID + WHERE name = 'default_membership_type_amount'" + ); + + } + return TRUE; + } + /** * Install CustomSearches extension. * diff --git a/xml/templates/civicrm_data.tpl b/xml/templates/civicrm_data.tpl index 873e8ed344..485509d346 100644 --- a/xml/templates/civicrm_data.tpl +++ b/xml/templates/civicrm_data.tpl @@ -1746,10 +1746,9 @@ VALUES -- CRM-9714 -SELECT @financial_type_id := max(id) FROM `civicrm_financial_type` WHERE `name` = 'Member Dues'; INSERT INTO `civicrm_price_set` ( `name`, `title`, `is_active`, `extends`, `is_quick_config`, `financial_type_id`, `is_reserved` ) VALUES ( 'default_contribution_amount', 'Contribution Amount', '1', '2', '1', NULL,1), -( 'default_membership_type_amount', 'Membership Amount', '1', '3', '1', @financial_type_id,1); +( 'default_membership_type_amount', 'Membership Amount', '1', '3', '1', @financial_type_id_md,1); SELECT @setID := max(id) FROM civicrm_price_set WHERE name = 'default_contribution_amount' AND extends = 2 AND is_quick_config = 1 ; -- 2.25.1