/** * 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(); } } }
/** * Store multiple items in the setting table. * * @param array $params * (required) An api formatted array of keys and values. * @param array $domains Array of domains to get settings for. Default is the current domain * @param $settingsToReturn * * @return array */ public static function getItems(&$params, $domains = NULL, $settingsToReturn) { $originalDomain = CRM_Core_Config::domainID(); if (empty($domains)) { $domains[] = $originalDomain; } if (!empty($settingsToReturn) && !is_array($settingsToReturn)) { $settingsToReturn = array($settingsToReturn); } $reloadConfig = FALSE; $fields = $result = array(); $fieldsToGet = self::validateSettingsInput(array_flip($settingsToReturn), $fields, FALSE); foreach ($domains as $domainID) { if ($domainID != CRM_Core_Config::domainID()) { $reloadConfig = TRUE; CRM_Core_BAO_Domain::setDomain($domainID); } $config = CRM_Core_Config::singleton($reloadConfig, $reloadConfig); $result[$domainID] = array(); foreach ($fieldsToGet as $name => $value) { $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 $result[$domainID][$name] = $setting; } } CRM_Core_BAO_Domain::resetDomain(); } return $result; }
/** * Setting api should set & fetch settings stored in config as well as those in settings table */ public function testSetConfigSetting() { $config = CRM_Core_Config::singleton(); $this->assertFalse($config->debug == 1); $params = array('domain_id' => $this->_domainID2, 'debug_enabled' => 1); $result = $this->callAPISuccess('setting', 'create', $params); CRM_Core_BAO_Domain::setDomain($this->_domainID2); $config = CRM_Core_Config::singleton(TRUE, TRUE); CRM_Core_BAO_Domain::resetDomain(); $this->assertTrue($config->debug == 1); // this should NOT be stored in the settings table now - only in config $sql = " SELECT count(*) as c FROM civicrm_setting WHERE name LIKE '%maxFileSize%'"; $dao = CRM_Core_DAO::executeQuery($sql); $dao->fetch(); $this->assertEquals($dao->c, 0); }
/** * Setting api should set & fetch settings stored in config as well as those in settings table */ public function testSetConfigSetting() { $config = CRM_Core_Config::singleton(); $this->assertFalse($config->debug == 1); $params = array('domain_id' => $this->_domainID2, 'debug_enabled' => 1); $result = $this->callAPISuccess('setting', 'create', $params); $this->assertEquals(1, Civi::settings($this->_domainID2)->get('debug_enabled')); CRM_Core_BAO_Domain::setDomain($this->_domainID2); $config = CRM_Core_Config::singleton(TRUE, TRUE); CRM_Core_BAO_Domain::resetDomain(); $this->assertEquals(1, $config->debug); }