X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FBAO%2FSetting.php;h=7ab3f5778fc666fb345504b5ec225621dd48c87b;hb=6f2500ee7589360102875df4367568fe87485df6;hp=2b1202c49080f2fd8b1f5eb49e35deac194bc7a2;hpb=a134e6ac6ffa73e67bb7f8da277734b9bd546121;p=civicrm-core.git diff --git a/CRM/Core/BAO/Setting.php b/CRM/Core/BAO/Setting.php index 2b1202c490..7ab3f5778f 100644 --- a/CRM/Core/BAO/Setting.php +++ b/CRM/Core/BAO/Setting.php @@ -1,7 +1,7 @@ delete($cacheKey); @@ -123,13 +126,14 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { /** * @param $values * @param $group - * @param null $componentID - * @param null $contactID - * @param null $domainID + * @param int $componentID + * @param int $contactID + * @param int $domainID * * @return string */ - static function setCache($values, + static function setCache( + $values, $group, $componentID = NULL, $contactID = NULL, @@ -152,13 +156,14 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { /** * @param $group * @param null $name - * @param null $componentID - * @param null $contactID - * @param null $domainID + * @param int $componentID + * @param int $contactID + * @param int $domainID * * @return CRM_Core_DAO_Domain|CRM_Core_DAO_Setting */ - static function dao($group, + static function dao( + $group, $name = NULL, $componentID = NULL, $contactID = NULL, @@ -197,17 +202,21 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { /** * Retrieve the value of a setting from the DB table * - * @param string $group (required) The group name of the item - * @param string $name (required) The name under which this item is stored - * @param int $componentID The optional component ID (so componenets can share the same name space) - * @param string $defaultValue The default value to return for this setting if not present in DB - * @param int $contactID If set, this is a contactID specific setting, else its a global setting + * @param string $group + * (required) The group name of the item. + * @param string $name + * (required) The name under which this item is stored. + * @param int $componentID + * The optional component ID (so componenets can share the same name space). + * @param string $defaultValue + * The default value to return for this setting if not present in DB. + * @param int $contactID + * If set, this is a contactID specific setting, else its a global setting. * - * @param null $domainID + * @param int $domainID * * @return mixed The data if present in the setting table, else null * @static - * @access public */ static function getItem( $group, @@ -252,16 +261,16 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { /** * Store multiple items in the setting table * - * @param array $params (required) An api formatted array of keys and values + * @param array $params + * (required) An api formatted array of keys and values. * @param null $domains * @param $settingsToReturn * * @domains array an array of domains to get settings for. Default is the current domain * @return void * @static - * @access public */ - static function getItems(&$params, $domains = NULL, $settingsToReturn) { + public static function getItems(&$params, $domains = NULL, $settingsToReturn) { $originalDomain = CRM_Core_Config::domainID(); if (empty($domains)) { $domains[] = $originalDomain; @@ -274,22 +283,22 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { $fields = $result = array(); $fieldsToGet = self::validateSettingsInput(array_flip($settingsToReturn), $fields, FALSE); foreach ($domains as $domainID) { - if($domainID != CRM_Core_Config::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) { - if(!empty($fields['values'][$name]['prefetch'])){ - if(isset($params['filters']) && isset($params['filters']['prefetch']) - && $params['filters']['prefetch'] == 0){ + if (!empty($fields['values'][$name]['prefetch'])) { + if (isset($params['filters']) && isset($params['filters']['prefetch']) + && $params['filters']['prefetch'] == 0) { // we are filtering out the prefetches from the return array // so we will skip continue; } $configKey = CRM_Utils_Array::value('config_key', $fields['values'][$name], $name); - if(isset($config->$configKey)){ + if (isset($config->$configKey)) { $setting = $config->$configKey; } } @@ -320,18 +329,22 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { * * _setItem() is the common logic shared by setItem() and setItems(). * - * @param object $value (required) The value that will be serialized and stored - * @param string $group (required) The group name of the item - * @param string $name (required) The name of the setting - * @param int $componentID The optional component ID (so componenets can share the same name space) - * @param null $contactID - * @param int $createdID An optional ID to assign the creator to. If not set, retrieved from session + * @param object $value + * (required) The value that will be serialized and stored. + * @param string $group + * (required) The group name of the item. + * @param string $name + * (required) The name of the setting. + * @param int $componentID + * The optional component ID (so componenets can share the same name space). + * @param int $contactID + * @param int $createdID + * An optional ID to assign the creator to. If not set, retrieved from session. * - * @param null $domainID + * @param int $domainID * * @return void * @static - * @access public */ static function setItem( $value, @@ -357,14 +370,15 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { * * _setItem() is the common logic shared by setItem() and setItems(). * - * @param array $metadata metadata describing this field + * @param array $metadata + * Metadata describing this field. * @param $value * @param $group - * @param $name - * @param null $componentID - * @param null $contactID - * @param null $createdID - * @param null $domainID + * @param string $name + * @param int $componentID + * @param int $contactID + * @param int $createdID + * @param int $domainID */ static function _setItem( $metadata, @@ -439,16 +453,16 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { * * _setItem() is the common logic shared by setItem() and setItems(). * - * @param array $params (required) An api formatted array of keys and values + * @param array $params + * (required) An api formatted array of keys and values. * @param null $domains * * @throws api_Exception * @domains array an array of domains to get settings for. Default is the current domain * @return array * @static - * @access public */ - static function setItems(&$params, $domains = NULL) { + public static function setItems(&$params, $domains = NULL) { $originalDomain = CRM_Core_Config::domainID(); if (empty($domains)) { $domains[] = $originalDomain; @@ -462,13 +476,13 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { } foreach ($domains as $domainID) { - if($domainID != CRM_Core_Config::domainID()){ + if ($domainID != CRM_Core_Config::domainID()) { $reloadConfig = TRUE; CRM_Core_BAO_Domain::setDomain($domainID); } $result[$domainID] = array(); foreach ($fieldsToSet as $name => $value) { - if(empty($fields['values'][$name]['config_only'])){ + if (empty($fields['values'][$name]['config_only'])) { CRM_Core_BAO_Setting::_setItem( $fields['values'][$name], $value, @@ -480,22 +494,22 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { $domainID ); } - if(!empty($fields['values'][$name]['prefetch'])){ - if(!empty($fields['values'][$name]['config_key'])){ + if (!empty($fields['values'][$name]['prefetch'])) { + if (!empty($fields['values'][$name]['config_key'])) { $name = $fields['values'][$name]['config_key']; } $config_keys[$name] = $value; } $result[$domainID][$name] = $value; } - if($reloadConfig){ + if ($reloadConfig) { CRM_Core_Config::singleton($reloadConfig, $reloadConfig); } - if(!empty($config_keys)){ + if (!empty($config_keys)) { CRM_Core_BAO_ConfigSetting::create($config_keys); } - if($reloadConfig){ + if ($reloadConfig) { CRM_Core_BAO_Domain::resetDomain(); } } @@ -504,18 +518,20 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { } /** - * gets metadata about the settings fields (from getfields) based on the fields being passed in + * Gets metadata about the settings fields (from getfields) based on the fields being passed in * * This function filters on the fields like 'version' & 'debug' that are not settings * - * @param array $params Parameters as passed into API - * @param array $fields empty array to be populated with fields metadata + * @param array $params + * Parameters as passed into API. + * @param array $fields + * Empty array to be populated with fields metadata. * @param bool $createMode * * @throws api_Exception * @return array $fieldstoset name => value array of the fields to be set (with extraneous removed) */ - static function validateSettingsInput($params, &$fields, $createMode = TRUE) { + public static function validateSettingsInput($params, &$fields, $createMode = TRUE) { $group = CRM_Utils_Array::value('group', $params); $ignoredParams = array( @@ -535,10 +551,11 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { 'IDS_user_agent', 'check_permissions', 'options', + 'prettyprint', ); $settingParams = array_diff_key($params, array_fill_keys($ignoredParams, TRUE)); $getFieldsParams = array('version' => 3); - if (count($settingParams) ==1) { + if (count($settingParams) == 1) { // ie we are only setting one field - we'll pass it into getfields for efficiency list($name) = array_keys($settingParams); $getFieldsParams['name'] = $name; @@ -546,7 +563,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { $fields = civicrm_api3('setting','getfields', $getFieldsParams); $invalidParams = (array_diff_key($settingParams, $fields['values'])); if (!empty($invalidParams)) { - throw new api_Exception(implode(',', $invalidParams) . " not valid settings"); + throw new api_Exception(implode(',', array_keys($invalidParams)) . " not valid settings"); } if (!empty($settingParams)) { $filteredFields = array_intersect_key($settingParams, $fields['values']); @@ -564,8 +581,8 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { * @value mixed value of the setting to be set * @fieldSpec array Metadata for given field (drawn from the xml) */ - static function validateSetting(&$value, $fieldSpec) { - if($fieldSpec['type'] == 'String' && is_array($value)){ + public static function validateSetting(&$value, $fieldSpec) { + if ($fieldSpec['type'] == 'String' && is_array($value)) { $value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR,$value) . CRM_Core_DAO::VALUE_SEPARATOR; } if (empty($fieldSpec['validate_callback'])) { @@ -585,7 +602,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { * @value mixed value of the setting to be set * @fieldSpec array Metadata for given field (drawn from the xml) */ - static function validateBoolSetting(&$value, $fieldSpec) { + public static function validateBoolSetting(&$value, $fieldSpec) { if (!CRM_Utils_Rule::boolean($value)) { throw new api_Exception("Boolean value required for {$fieldSpec['name']}"); } @@ -612,7 +629,8 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { * * The following params will filter the result. If none are passed all settings will be returns * - * @param int $componentID id of relevant component + * @param int $componentID + * Id of relevant component. * @param array $filters * @param int $domainID * @param null $profile @@ -645,7 +663,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { $settingsMetadata = CRM_Core_BAO_Cache::getItem('CiviCRM setting Spec', 'All', $componentID); if (empty($settingsMetadata)) { global $civicrm_root; - $metaDataFolders = array($civicrm_root. '/settings'); + $metaDataFolders = array($civicrm_root . '/settings'); CRM_Utils_Hook::alterSettingsFolders($metaDataFolders); $settingsMetadata = self::loadSettingsMetaDataFolders($metaDataFolders); CRM_Core_BAO_Cache::setItem($settingsMetadata,'CiviCRM setting Spec', 'All', $componentID); @@ -673,7 +691,8 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { /** * Load the settings files defined in a series of folders - * @param array $metaDataFolders list of folder paths + * @param array $metaDataFolders + * List of folder paths. * @return array */ public static function loadSettingsMetaDataFolders($metaDataFolders) { @@ -692,7 +711,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { /** * Load up settings metadata from files */ - static function loadSettingsMetadata($metaDataFolder) { + public static function loadSettingsMetadata($metaDataFolder) { $settingMetaData = array(); $settingsFiles = CRM_Utils_File::findFiles($metaDataFolder, '*.setting.php'); foreach ($settingsFiles as $file) { @@ -707,14 +726,16 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { * Filter the settings metadata according to filters passed in. This is a convenience filter * and allows selective reverting / filling of settings * - * @param array $filters Filters to match against data - * @param array $settingSpec metadata to filter + * @param array $filters + * Filters to match against data. + * @param array $settingSpec + * Metadata to filter. */ - static function _filterSettingsSpecification($filters, &$settingSpec) { + public static function _filterSettingsSpecification($filters, &$settingSpec) { if (empty($filters)) { return; } - else if (array_keys($filters) == array('name')) { + elseif (array_keys($filters) == array('name')) { $settingSpec = array($filters['name'] => CRM_Utils_Array::value($filters['name'], $settingSpec, '')); return; } @@ -735,7 +756,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { * Multisites have often been overlooked in upgrade scripts so can be expected to be missing * a number of settings */ - static function updateSettingsFromMetaData() { + public static function updateSettingsFromMetaData() { $apiParams = array( 'version' => 3, 'domain_id' => 'all', @@ -757,30 +778,31 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { } /** - * move an item from being in the config array to being stored as a setting + * 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 */ - static function convertConfigToSetting($name, $domainID = NULL) { + 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(); + $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 { + } + 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 the key is set to config_only we don't need to do anything - if(empty($spec[$name]['config_only'])){ + if (empty($spec[$name]['config_only'])) { if (!empty($values[$configKey])) { civicrm_api('setting', 'create', array('version' => 3, $name => $values[$configKey], 'domain_id' => $domainID)); } @@ -799,9 +821,9 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { /** * @param $group - * @param $name + * @param string $name * @param bool $system - * @param null $userID + * @param int $userID * @param bool $localize * @param string $returnField * @param bool $returnNameANDLabels @@ -809,7 +831,8 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { * * @return array */ - static function valueOptions($group, + static function valueOptions( + $group, $name, $system = TRUE, $userID = NULL, @@ -861,13 +884,14 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { /** * @param $group - * @param $name + * @param string $name * @param $value * @param bool $system - * @param null $userID + * @param int $userID * @param string $keyField */ - static function setValueOption($group, + static function setValueOption( + $group, $name, $value, $system = TRUE, @@ -905,9 +929,9 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { /** * @param array $params - * @param null $domainID + * @param int $domainID */ - static function fixAndStoreDirAndURL(&$params, $domainID = NULL) { + public static function fixAndStoreDirAndURL(&$params, $domainID = NULL) { if (self::isUpgradeFromPreFourOneAlpha1()) { return; } @@ -982,7 +1006,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { * @param array $params * @param $group */ - static function storeDirectoryOrURLPreferences(&$params, $group) { + public static function storeDirectoryOrURLPreferences(&$params, $group) { foreach ($params as $name => $value) { // always try to store relative directory or url from CMS root $value = ($group == self::DIRECTORY_PREFERENCES_NAME) ? CRM_Utils_File::relativeDirectory($value) : CRM_Utils_System::relativeURL($value); @@ -995,7 +1019,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { * @param array $params * @param bool $setInConfig */ - static function retrieveDirectoryAndURLPreferences(&$params, $setInConfig = FALSE) { + public static function retrieveDirectoryAndURLPreferences(&$params, $setInConfig = FALSE) { if (CRM_Core_Config::isUpgradeMode()) { $isJoomla = (defined('CIVICRM_UF') && CIVICRM_UF == 'Joomla') ? TRUE : FALSE; // hack to set the resource base url so that js/ css etc is loaded correctly @@ -1067,7 +1091,7 @@ AND domain_id = %3 * for a setting. * * @param $group - * @param $name + * @param string $name * @param $default * * @return mixed, NULL or an overriden value @@ -1083,11 +1107,11 @@ AND domain_id = %3 } /** - * civicrm_setting didn't exist before 4.1.alpha1 and this function helps taking decisions during upgrade + * Civicrm_setting didn't exist before 4.1.alpha1 and this function helps taking decisions during upgrade * * @return boolean */ - static function isUpgradeFromPreFourOneAlpha1() { + public static function isUpgradeFromPreFourOneAlpha1() { if (CRM_Core_Config::isUpgradeMode()) { $currentVer = CRM_Core_BAO_Domain::version(); if (version_compare($currentVer, '4.1.alpha1') < 0) {