dev/core#2786 Ensure non-English installs have a default financial type for membershi...
authorEileen McNaughton <emcnaughton@wikimedia.org>
Sat, 28 Aug 2021 00:21:34 +0000 (12:21 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Sat, 28 Aug 2021 23:36:05 +0000 (11:36 +1200)
CRM/Upgrade/Incremental/php/FiveFortyOne.php
xml/templates/civicrm_data.tpl

index 027f0be9c13215eac539909caf962fc6504c16b6..cab70b9c26e4c07beba3f98f900c8c655fa7aaee 100644 (file)
@@ -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.
    *
index 873e8ed3442ba2c0c80e293ff5189bdb588bb217..485509d3469a667d794df107c3ab2fad413f6f78 100644 (file)
@@ -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 ;