From 84d52986c4ebd93b55741bc62dcabe2c8a4e610e Mon Sep 17 00:00:00 2001 From: Tim Otten <totten@civicrm.org> Date: Tue, 28 Apr 2020 21:54:12 -0700 Subject: [PATCH] dev/core#1724 - Backward-compatible handling of 'contribution_invoice_settings.invoicing' In the old setting `contribution_invoice_settings`, the `invoicing` property (aka "CiviContribute Component Settings" => "Enable Tax and Invoicing") could take one of two values: 1. If enabled, it's an array with trueish subkey: `['invoicing'=>1]` 2. If disabled, it's a numeric zero. This encoding is weird, and `contribution_invoice_settings` is generally deprecated and has been replaced by a virtual rendition which needs to be consistent with the old representation -- so that a couple-dozen things continue working. For testing, it helped me to try these commands at different points: ``` cv ev 'return CRM_Invoicing_Utils::isInvoicingEnabled();' cv api setting.get return=invoicing cv api setting.get return=contribution_invoice_settings select * from civicrm_setting where name like 'contrib%' or name like 'invoic%'; ``` --- Civi/Core/SettingsBag.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Civi/Core/SettingsBag.php b/Civi/Core/SettingsBag.php index 3435fd3114f..be51cc6ae41 100644 --- a/Civi/Core/SettingsBag.php +++ b/Civi/Core/SettingsBag.php @@ -287,6 +287,9 @@ class SettingsBag { if ($key === 'contribution_invoice_settings') { foreach (SettingsBag::getContributionInvoiceSettingKeys() as $possibleKeyName => $settingName) { $keyValue = $value[$possibleKeyName] ?? ''; + if ($possibleKeyName === 'invoicing' && is_array($keyValue)) { + $keyValue = $keyValue['invoicing']; + } $this->set($settingName, $keyValue); } return TRUE; @@ -302,7 +305,15 @@ class SettingsBag { public function computeVirtual() { $contributionSettings = []; foreach (SettingsBag::getContributionInvoiceSettingKeys() as $keyName => $settingName) { - $contributionSettings[$keyName] = $this->get($settingName); + switch ($keyName) { + case 'invoicing': + $contributionSettings[$keyName] = $this->get($settingName) ? [$keyName => 1] : 0; + break; + + default: + $contributionSettings[$keyName] = $this->get($settingName); + break; + } } return ['contribution_invoice_settings' => $contributionSettings]; } -- GitLab