Пример #1
0
 /**
  * Store multiple items in the setting table. Note that this will also store config keys
  * the storage is determined by the metdata and is affected by
  *  'name' setting's name
  *  'prefetch' = store in config
  *  'config_only' = don't store in settings
  *  'config_key' = the config key is different to the settings key - e.g. debug where there was a conflict
  *  'legacy_key' = rename from config or setting with this name
  *
  * _setItem() is the common logic shared by setItem() and setItems().
  *
  * @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
  */
 public static function setItems(&$params, $domains = NULL)
 {
     $originalDomain = CRM_Core_Config::domainID();
     if (empty($domains)) {
         $domains[] = $originalDomain;
     }
     $reloadConfig = FALSE;
     $fields = $config_keys = array();
     $fieldsToSet = self::validateSettingsInput($params, $fields);
     foreach ($fieldsToSet as $settingField => &$settingValue) {
         self::validateSetting($settingValue, $fields['values'][$settingField]);
     }
     foreach ($domains as $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'])) {
                 CRM_Core_BAO_Setting::_setItem($fields['values'][$name], $value, $fields['values'][$name]['group_name'], $name, CRM_Utils_Array::value('component_id', $params), CRM_Utils_Array::value('contact_id', $params), CRM_Utils_Array::value('created_id', $params), $domainID);
             }
             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) {
             CRM_Core_Config::singleton($reloadConfig, $reloadConfig);
         }
         if (!empty($config_keys)) {
             CRM_Core_BAO_ConfigSetting::create($config_keys);
         }
         if ($reloadConfig) {
             CRM_Core_BAO_Domain::resetDomain();
         }
     }
     return $result;
 }