$config = CRM_Core_Config::singleton($reloadConfig, $reloadConfig);
$result[$domainID] = array();
foreach ($fieldsToGet as $name => $value) {
- $setting = CRM_Core_BAO_Setting::getItem(
- $fields['values'][$name]['group_name'],
- $name,
- CRM_Utils_Array::value('component_id', $params),
- NULL,
- CRM_Utils_Array::value('contact_id', $params),
- $domainID
- );
+ $contactID = CRM_Utils_Array::value('contact_id', $params);
+ $setting = CRM_Core_BAO_Setting::getItem(NULL, $name, NULL, NULL, $contactID, $domainID);
if (!is_null($setting)) {
// we won't return if not set - helps in return all scenario - otherwise we can't indentify the missing ones
// e.g for revert of fill actions
return \Civi\Core\SettingsMetadata::getMetadata($filters, $domainID);
}
- /**
- * Look for any missing settings and convert them from config or load default as appropriate.
- * This should be run from GenCode & also from upgrades to add any new defaults.
- *
- * Multisites have often been overlooked in upgrade scripts so can be expected to be missing
- * a number of settings
- */
- public static function updateSettingsFromMetaData() {
- $apiParams = array(
- 'version' => 3,
- 'domain_id' => 'all',
- 'filters' => array('prefetch' => 0),
- );
- $existing = civicrm_api('setting', 'get', $apiParams);
-
- if (!empty($existing['values'])) {
- $allSettings = civicrm_api('setting', 'getfields', array('version' => 3));
- foreach ($existing['values'] as $domainID => $domainSettings) {
- CRM_Core_BAO_Domain::setDomain($domainID);
- $missing = array_diff_key($allSettings['values'], $domainSettings);
- foreach ($missing as $name => $settings) {
- self::convertConfigToSetting($name, $domainID);
- }
- CRM_Core_BAO_Domain::resetDomain();
- }
- }
- }
-
- /**
- * Move an item from being in the config array to being stored as a setting
- * remove from config - as appropriate based on metadata
- *
- * Note that where the key name is being changed the 'legacy_key' will give us the old name
- */
- public static function convertConfigToSetting($name, $domainID = NULL) {
- // we have to force this here in case more than one domain is in play.
- // whenever there is a possibility of more than one domain we must force it
- $config = CRM_Core_Config::singleton();
- if (empty($domainID)) {
- $domainID = CRM_Core_Config::domainID();
- }
- $domain = new CRM_Core_DAO_Domain();
- $domain->id = $domainID;
- $domain->find(TRUE);
- if ($domain->config_backend) {
- $values = unserialize($domain->config_backend);
- }
- else {
- $values = array();
- }
- $spec = self::getSettingSpecification(NULL, array('name' => $name), $domainID);
- $configKey = CRM_Utils_Array::value('config_key', $spec[$name], CRM_Utils_Array::value('legacy_key', $spec[$name], $name));
- if (!empty($values[$configKey])) {
- civicrm_api('setting', 'create', array('version' => 3, $name => $values[$configKey], 'domain_id' => $domainID));
- }
- else {
- civicrm_api('setting', 'fill', array('version' => 3, 'name' => $name, 'domain_id' => $domainID));
- }
-
- if (!empty($values[$configKey])) {
- unset($values[$configKey]);
- $domain->config_backend = serialize($values);
- $domain->save();
- }
- }
-
/**
* @param $group
* @param string $name
$this->assertEquals('/test/override', $values['imageUploadDir']);
}
- /**
- * This test checks that CRM_Core_BAO_Setting::updateSettingsFromMetaData();
- * 1) Removes 'maxAttachments' from config (because 'prefetch' is not set in the metadata it should
- * be removed
- * 2) for current domain setting max_attachments is set to the value that $config->maxAttachments
- * had (6)
- * 3) for other domain (2) max_attachments is set to the configured default (3)
- */
- public function testConvertAndFillSettings() {
- $settings = array('maxAttachments' => 6);
- CRM_Core_BAO_ConfigSetting::add($settings);
- $config = CRM_Core_Config::singleton(TRUE, TRUE);
- $this->assertEquals(6, $config->maxAttachments);
- $checkSQL = "SELECT count(*) FROM civicrm_domain WHERE config_backend LIKE '%\"maxAttachments\";i:6%' AND id = 1
- ";
- $checkresult = CRM_Core_DAO::singleValueQuery($checkSQL);
- $this->assertEquals(1, $checkresult, "Check that maxAttachments has been saved to database not just stored in config");
- $sql = " DELETE FROM civicrm_setting WHERE name = 'max_attachments'";
- CRM_Core_DAO::executeQuery($sql);
-
- $currentDomain = CRM_Core_Config::domainID();
- // we are setting up an artificial situation here as we are trying to drive out
- // previous memory of this setting so we need to flush it out
- //$cachekey = CRM_Core_BAO_Setting::inCache('CiviCRM Preferences', 'max_attachments', NULL, NULL, TRUE, $currentDomain);
- //CRM_Core_BAO_Setting::flushCache($cachekey);
+ public function testDefaults() {
+ CRM_Core_DAO::executeQuery('DELETE FROM civicrm_setting WHERE name = "max_attachments"');
Civi::service('settings_manager')->flush();
- CRM_Core_BAO_Setting::updateSettingsFromMetaData();
- //check current domain
- $value = civicrm_api('setting', 'getvalue', array(
- 'version' => 3,
- 'name' => 'max_attachments',
- 'group' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
- ));
-
- $this->assertEquals(6, $value);
- // check alternate domain
- $value = civicrm_api('setting', 'getvalue', array(
- 'version' => 3,
- 'name' => 'max_attachments',
- 'group' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
- 'domain_id' => 2,
- ));
-
- $this->assertEquals(3, $value);
-
- //some caching inconsistency here
- $config = CRM_Core_Config::singleton(TRUE, TRUE);
- $maxAttachments = empty($config->maxAttachments) ? NULL : $config->maxAttachments;
- $this->assertEmpty($maxAttachments, "Config item still Set to $maxAttachments
- . This works fine when test run alone");
- }
-
- /**
- * Ensure that overrides in $civicrm_setting apply when
- * when using getItem().
- */
- public function testConvertConfigToSettingNoPrefetch() {
- $settings = array('maxAttachments' => 6);
- CRM_Core_BAO_ConfigSetting::add($settings);
- $config = CRM_Core_Config::singleton(TRUE, TRUE);
- $this->assertEquals(6, $config->maxAttachments);
-
- CRM_Core_BAO_Setting::convertConfigToSetting('max_attachments');
- $value = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'max_attachments');
- $this->assertEquals(6, $value);
-
- $this->callAPISuccess('system', 'flush', array());
- $config = CRM_Core_Config::singleton(TRUE, TRUE);
- $maxAttachments = empty($config->maxAttachments) ? NULL : $config->maxAttachments;
- $this->assertEmpty($maxAttachments);
- }
-
- /* @codingStandardsIgnoreStart
- * Check that setting is converted without config value being removed
- *
- public function testConvertConfigToSettingPrefetch() {
- $settings = array('debug' => 1);
- CRM_Core_BAO_ConfigSetting::add($settings);
- $config = CRM_Core_Config::singleton(true, true);
- $this->assertEquals(1, $config->debug);
- CRM_Core_BAO_Setting::convertConfigToSetting('debug_is_enabled');
- $value = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::DEBUG_PREFERENCES_NAME, 'debug_is_enabled');
- $this->assertEquals(1, $value);
- civicrm_api('system', 'flush', array('version' => 3));
- $config = CRM_Core_Config::singleton(true, true);
- $this->assertEmpty($config->debug);
+ $this->assertEquals(3, Civi::settings()->get('max_attachments'));
+ $this->assertEquals(3, CRM_Core_Config::singleton()->maxAttachments);
}
- @codingStandardsIgnoreEnd */
/**
* Ensure that on_change callbacks fire.