X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=Civi%2FCore%2FSettingsBag.php;h=779bc3a2302f0df8b769dca98a59c6baf8e291d1;hb=ff6f993e56bf4f87caa0317ea3d1f883956b74da;hp=7ca5ec4ad707554ece1ba17945edd3ff7149df0f;hpb=8991fd426febffc0b62bb252f756a67fe96c114a;p=civicrm-core.git diff --git a/Civi/Core/SettingsBag.php b/Civi/Core/SettingsBag.php index 7ca5ec4ad7..779bc3a230 100644 --- a/Civi/Core/SettingsBag.php +++ b/Civi/Core/SettingsBag.php @@ -1,27 +1,11 @@ createQuery()->toSQL()); while ($dao->fetch()) { - $this->values[$dao->name] = ($dao->value !== NULL) ? unserialize($dao->value) : NULL; + $this->values[$dao->name] = ($dao->value !== NULL) ? \CRM_Utils_String::unserialize($dao->value) : NULL; } + $dao->values['contribution_invoice_settings'] = $this->getContributionSettings(); } return $this; @@ -269,12 +254,51 @@ class SettingsBag { * @return SettingsBag */ public function set($key, $value) { + if ($key === 'contribution_invoice_settings') { + $this->setContributionSettings($value); + return $this; + } $this->setDb($key, $value); $this->values[$key] = $value; $this->combined = NULL; return $this; } + /** + * Temporary handling for phasing out contribution_invoice_settings. + * + * Until we have transitioned we need to handle setting & retrieving + * contribution_invoice_settings. + * + * Once removed from core we will add deprecation notices & then remove this. + * + * https://lab.civicrm.org/dev/core/issues/1558 + * + * @param array $value + */ + public function setContributionSettings($value) { + foreach (SettingsBag::getContributionInvoiceSettingKeys() as $possibleKeyName => $settingName) { + $keyValue = $value[$possibleKeyName] ?? ''; + $this->set($settingName, $keyValue); + } + $this->values['contribution_invoice_settings'] = $this->getContributionSettings(); + } + + /** + * Temporary function to handle returning the contribution_settings key despite it being deprecated. + * + * See more in comment block on previous function. + * + * @return array + */ + public function getContributionSettings() { + $contributionSettings = []; + foreach (SettingsBag::getContributionInvoiceSettingKeys() as $keyName => $settingName) { + $contributionSettings[$keyName] = $this->values[$settingName] ?? ''; + } + return $contributionSettings; + } + /** * @return \CRM_Utils_SQL_Select */ @@ -355,7 +379,7 @@ class SettingsBag { foreach ($metadata['on_change'] as $callback) { call_user_func( \Civi\Core\Resolver::singleton()->get($callback), - unserialize($dao->value), + \CRM_Utils_String::unserialize($dao->value), $value, $metadata, $this->domainId @@ -394,4 +418,22 @@ class SettingsBag { } } + /** + * @return array + */ + public static function getContributionInvoiceSettingKeys(): array { + $convertedKeys = [ + 'credit_notes_prefix' => 'credit_notes_prefix', + 'invoice_prefix' => 'invoice_prefix', + 'due_date' => 'invoice_due_date', + 'due_date_period' => 'invoice_due_date_period', + 'notes' => 'invoice_notes', + 'is_email_pdf' => 'invoice_is_email_pdf', + 'tax_term' => 'tax_term', + 'tax_display_settings' => 'tax_display_settings', + 'invoicing' => 'invoicing', + ]; + return $convertedKeys; + } + }