Skip to content
Snippets Groups Projects
Commit 84d52986 authored by totten's avatar totten
Browse files

#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%';
```
parent 6f306db3
No related branches found
No related tags found
No related merge requests found
......@@ -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];
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment