dev/core#2719 [REF] Deprecate legacy references to contribution_invoice_settings
authorEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 29 Jul 2021 00:45:18 +0000 (12:45 +1200)
committereileen <emcnaughton@wikimedia.org>
Thu, 4 Jan 2024 23:09:30 +0000 (12:09 +1300)
Civi/Core/SettingsBag.php
api/v3/Setting.php
tests/phpunit/CRM/Core/BAO/SettingTest.php

index 948ea2b96312c7fd72c6b3ec43338d0ab8c88408..2c03016024a345ce4a23b164c298f062ff86e293 100644 (file)
@@ -270,6 +270,7 @@ class SettingsBag {
    */
   public function updateVirtual($key, $value) {
     if ($key === 'contribution_invoice_settings') {
+      \CRM_Core_Error::deprecatedWarning('Invoicing settings should be directly accessed - eg Civi::setting()->set("invoicing")');
       foreach (SettingsBag::getContributionInvoiceSettingKeys() as $possibleKeyName => $settingName) {
         $keyValue = $value[$possibleKeyName] ?? '';
         if ($possibleKeyName === 'invoicing' && is_array($keyValue)) {
index a2c422bb710481c57896d7e5b0805a13ca33ec1a..605ae2734df879eb82a1058b3b60dd1ca9353432 100644 (file)
@@ -296,7 +296,11 @@ function _civicrm_api3_setting_create_spec(&$params) {
  */
 function civicrm_api3_setting_get($params) {
   $domains = _civicrm_api3_setting_getDomainArray($params);
-  $result = CRM_Core_BAO_Setting::getItems($params, $domains, $params['return'] ?? []);
+  $returnSettings = (array) ($params['return'] ?? []);
+  if (in_array('contribution_invoice_settings', $returnSettings)) {
+    CRM_Core_Error::deprecatedWarning('contribution_invoice_settings is not a valid setting. Request the actual setting');
+  }
+  $result = CRM_Core_BAO_Setting::getItems($params, $domains, $returnSettings);
   return civicrm_api3_create_success($result, $params, 'Setting', 'get');
 }
 
index 79ed20f4b81262435cfab76012b473079ad6fd44..b1412983e983a5ae92d09d5baabfbcaf774e8ebc 100644 (file)
@@ -69,50 +69,6 @@ class CRM_Core_BAO_SettingTest extends CiviUnitTestCase {
     $this->assertFalse($result);
   }
 
-  /**
-   * Test temporary retrieval & setting of converted settings.
-   *
-   * As a transitional measure we allow the settings that were munged into
-   * contribution_invoice_setting. This tests that the current method of getting via the 'old' key
-   * works. This will be deprecated & removed over the next few versions but
-   * 1) some extensions use these settings &
-   * 2) there is a lot of work to fix this mess in core so a transitional method makes sense.
-   *
-   * https://lab.civicrm.org/dev/core/issues/1558
-   *
-   * @throws \CRM_Core_Exception
-   */
-  public function testHandlingOfContributionInvoiceSetting(): void {
-    $contributionSettings = [
-      'invoice_prefix' => 'G_',
-      'credit_notes_prefix' => 'XX_',
-      'due_date' => '20',
-      'due_date_period' => 'weeks',
-      'notes' => '<p>Give me money</p>',
-      'tax_term' => 'Extortion',
-      'tax_display_settings' => 'Exclusive',
-      // NOTE: This form of `invoicing` is accepted, but it may be normalized to the idiomatic form with a nested array.
-      'invoicing' => 1,
-      'is_email_pdf' => '1',
-    ];
-    Civi::settings()->set('contribution_invoice_settings', $contributionSettings);
-    $settingsFromGet = Civi::settings()->get('contribution_invoice_settings');
-    $settingsFromAPI = $this->callAPISuccess('Setting', 'get', ['return' => 'contribution_invoice_settings'])['values'][CRM_Core_Config::domainID()]['contribution_invoice_settings'];
-    $getVersion = $this->callAPISuccessGetValue('Setting', ['name' => 'contribution_invoice_settings']);
-    $this->assertEquals($settingsFromAPI, $settingsFromGet);
-    $this->assertAPIArrayComparison($getVersion, $settingsFromGet);
-    $this->assertEquals(['invoicing' => ['invoicing' => 1]] + $contributionSettings, $settingsFromGet);
-
-    // These are the preferred retrieval methods.
-    $this->assertEquals('G_', Civi::settings()->get('invoice_prefix'));
-    $this->assertEquals('XX_', Civi::settings()->get('credit_notes_prefix'));
-    $this->assertEquals('20', Civi::settings()->get('invoice_due_date'));
-    $this->assertEquals('weeks', Civi::settings()->get('invoice_due_date_period'));
-    $this->assertEquals('<p>Give me money</p>', Civi::settings()->get('invoice_notes'));
-    $this->assertEquals('Extortion', Civi::settings()->get('tax_term'));
-    $this->assertEquals('Exclusive', Civi::settings()->get('tax_display_settings'));
-  }
-
   /**
    * Ensure that overrides in $civicrm_setting apply when
    * using getItem($group,$name).