Пример #1
0
 /**
  * Initialize the config variables.
  *
  * @return void
  */
 private function _initVariables()
 {
     // retrieve serialised settings
     $variables = array();
     CRM_Core_BAO_ConfigSetting::retrieve($variables);
     // if settings are not available, go down the full path
     if (empty($variables)) {
         // Step 1. get system variables with their hardcoded defaults
         $variables = get_object_vars($this);
         // Step 2. get default values (with settings file overrides if
         // available - handled in CRM_Core_Config_Defaults)
         CRM_Core_Config_Defaults::setValues($variables);
         // retrieve directory and url preferences also
         CRM_Core_BAO_Setting::retrieveDirectoryAndURLPreferences($variables);
         // add component specific settings
         $this->componentRegistry->addConfig($this);
         // serialise settings
         $settings = $variables;
         CRM_Core_BAO_ConfigSetting::add($settings);
     }
     $urlArray = array('userFrameworkResourceURL', 'imageUploadURL');
     $dirArray = array('uploadDir', 'customFileUploadDir');
     foreach ($variables as $key => $value) {
         if (in_array($key, $urlArray)) {
             $value = CRM_Utils_File::addTrailingSlash($value, '/');
         } elseif (in_array($key, $dirArray)) {
             if ($value) {
                 $value = CRM_Utils_File::addTrailingSlash($value);
             }
             if (empty($value) || CRM_Utils_File::createDir($value, FALSE) === FALSE) {
                 // seems like we could not create the directories
                 // settings might have changed, lets suppress a message for now
                 // so we can make some more progress and let the user fix their settings
                 // for now we assign it to a know value
                 // CRM-4949
                 $value = $this->templateCompileDir;
                 $url = CRM_Utils_System::url('civicrm/admin/setting/path', 'reset=1');
                 CRM_Core_Session::setStatus(ts('%1 has an incorrect directory path. Please go to the <a href="%2">path setting page</a> and correct it.', array(1 => $key, 2 => $url)), ts('Check Settings'), 'alert');
             }
         } elseif ($key == 'lcMessages') {
             // reset the templateCompileDir to locale-specific and make sure it exists
             if (substr($this->templateCompileDir, -1 * strlen($value) - 1, -1) != $value) {
                 $this->templateCompileDir .= CRM_Utils_File::addTrailingSlash($value);
                 CRM_Utils_File::createDir($this->templateCompileDir);
                 CRM_Utils_File::restrictAccess($this->templateCompileDir);
             }
         }
         $this->{$key} = $value;
     }
     if ($this->userFrameworkResourceURL) {
         // we need to do this here so all blocks also load from an ssl server
         if (CRM_Utils_System::isSSL()) {
             CRM_Utils_System::mapConfigToSSL();
         }
         $rrb = parse_url($this->userFrameworkResourceURL);
         // don't use absolute path if resources are stored on a different server
         // CRM-4642
         $this->resourceBase = $this->userFrameworkResourceURL;
         if (isset($_SERVER['HTTP_HOST']) && isset($rrb['host'])) {
             $this->resourceBase = $rrb['host'] == $_SERVER['HTTP_HOST'] ? $rrb['path'] : $this->userFrameworkResourceURL;
         }
     }
     if (!$this->customFileUploadDir) {
         $this->customFileUploadDir = $this->uploadDir;
     }
     if ($this->geoProvider) {
         $this->geocodeMethod = 'CRM_Utils_Geocode_' . $this->geoProvider;
     } elseif ($this->mapProvider) {
         $this->geocodeMethod = 'CRM_Utils_Geocode_' . $this->mapProvider;
     }
     require_once str_replace('_', DIRECTORY_SEPARATOR, $this->userFrameworkClass) . '.php';
     $class = $this->userFrameworkClass;
     // redundant with _setUserFrameworkConfig
     $this->userSystem = new $class();
 }
Пример #2
0
 /**
  * Retrieve the settings values from db.
  *
  * @param $defaults
  *
  * @return array
  */
 public static function retrieve(&$defaults)
 {
     $domain = new CRM_Core_DAO_Domain();
     //we are initializing config, really can't use, CRM-7863
     $urlVar = 'q';
     if (defined('CIVICRM_UF') && CIVICRM_UF == 'Joomla') {
         $urlVar = 'task';
     }
     if (CRM_Core_Config::isUpgradeMode()) {
         $domain->selectAdd('config_backend');
     } elseif (CRM_Utils_Array::value($urlVar, $_GET) == 'admin/modules/list/confirm') {
         $domain->selectAdd('config_backend', 'locales');
     } else {
         $domain->selectAdd('config_backend, locales, locale_custom_strings');
     }
     $domain->id = CRM_Core_Config::domainID();
     $domain->find(TRUE);
     if ($domain->config_backend) {
         $defaults = unserialize($domain->config_backend);
         if ($defaults === FALSE || !is_array($defaults)) {
             $defaults = array();
             return FALSE;
         }
         $skipVars = self::skipVars();
         foreach ($skipVars as $skip) {
             if (array_key_exists($skip, $defaults)) {
                 unset($defaults[$skip]);
             }
         }
         // check if there are any locale strings
         if ($domain->locale_custom_strings) {
             $defaults['localeCustomStrings'] = unserialize($domain->locale_custom_strings);
         } else {
             $defaults['localeCustomStrings'] = NULL;
         }
         // are we in a multi-language setup?
         $multiLang = $domain->locales ? TRUE : FALSE;
         // set the current language
         $lcMessages = NULL;
         $session = CRM_Core_Session::singleton();
         // on multi-lang sites based on request and civicrm_uf_match
         if ($multiLang) {
             $lcMessagesRequest = CRM_Utils_Request::retrieve('lcMessages', 'String', $this);
             $languageLimit = array();
             if (array_key_exists('languageLimit', $defaults) && is_array($defaults['languageLimit'])) {
                 $languageLimit = $defaults['languageLimit'];
             }
             if (in_array($lcMessagesRequest, array_keys($languageLimit))) {
                 $lcMessages = $lcMessagesRequest;
                 //CRM-8559, cache navigation do not respect locale if it is changed, so reseting cache.
                 CRM_Core_BAO_Cache::deleteGroup('navigation');
             } else {
                 $lcMessagesRequest = NULL;
             }
             if (!$lcMessagesRequest) {
                 $lcMessagesSession = $session->get('lcMessages');
                 if (in_array($lcMessagesSession, array_keys($languageLimit))) {
                     $lcMessages = $lcMessagesSession;
                 } else {
                     $lcMessagesSession = NULL;
                 }
             }
             if ($lcMessagesRequest) {
                 $ufm = new CRM_Core_DAO_UFMatch();
                 $ufm->contact_id = $session->get('userID');
                 if ($ufm->find(TRUE)) {
                     $ufm->language = $lcMessages;
                     $ufm->save();
                 }
                 $session->set('lcMessages', $lcMessages);
             }
             if (!$lcMessages and $session->get('userID')) {
                 $ufm = new CRM_Core_DAO_UFMatch();
                 $ufm->contact_id = $session->get('userID');
                 if ($ufm->find(TRUE) && in_array($ufm->language, array_keys($languageLimit))) {
                     $lcMessages = $ufm->language;
                 }
                 $session->set('lcMessages', $lcMessages);
             }
         }
         global $dbLocale;
         // try to inherit the language from the hosting CMS
         if (!empty($defaults['inheritLocale'])) {
             // FIXME: On multilanguage installs, CRM_Utils_System::getUFLocale() in many cases returns nothing if $dbLocale is not set
             $dbLocale = $multiLang ? "_{$defaults['lcMessages']}" : '';
             $lcMessages = CRM_Utils_System::getUFLocale();
             if ($domain->locales and !in_array($lcMessages, explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales))) {
                 $lcMessages = NULL;
             }
         }
         if (empty($lcMessages)) {
             //CRM-11993 - if a single-lang site, use default
             $lcMessages = CRM_Utils_Array::value('lcMessages', $defaults);
         }
         // set suffix for table names - use views if more than one language
         $dbLocale = $multiLang ? "_{$lcMessages}" : '';
         // FIXME: an ugly hack to fix CRM-4041
         global $tsLocale;
         $tsLocale = $lcMessages;
         // FIXME: as bad aplace as any to fix CRM-5428
         // (to be moved to a sane location along with the above)
         if (function_exists('mb_internal_encoding')) {
             mb_internal_encoding('UTF-8');
         }
     }
     // dont add if its empty
     if (!empty($defaults)) {
         // retrieve directory and url preferences also
         CRM_Core_BAO_Setting::retrieveDirectoryAndURLPreferences($defaults);
         // Pickup enabled-components from settings table if found.
         $enableComponents = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enable_components', NULL, array());
         if (!empty($enableComponents)) {
             $defaults['enableComponents'] = $enableComponents;
             $components = CRM_Core_Component::getComponents();
             $enabledComponentIDs = array();
             foreach ($defaults['enableComponents'] as $name) {
                 $enabledComponentIDs[] = $components[$name]->componentID;
             }
             $defaults['enableComponentIDs'] = $enabledComponentIDs;
         }
     }
 }
Пример #3
0
 /**
  * Ensure that overrides in $civicrm_setting apply when
  * when using retrieveDirectoryAndURLPreferences().
  */
 function testRetrieveDirectoryAndURLPreferences_Override()
 {
     global $civicrm_setting;
     $civicrm_setting[CRM_Core_BAO_Setting::DIRECTORY_PREFERENCES_NAME]['imageUploadDir'] = '/test/override';
     $params = array();
     CRM_Core_BAO_Setting::retrieveDirectoryAndURLPreferences($params);
     $this->assertEquals('/test/override', $params['imageUploadDir']);
 }