public function testSugarArrayMergeMergesTwoArraysWithLikeKeysOverwritingExistingKeys()
 {
     $foo = array('one' => 123, 'two' => 123, 'foo' => array('int' => 123, 'foo' => 'bar'));
     $bar = array('one' => 123, 'two' => 321, 'foo' => array('int' => 123, 'bar' => 'foo'));
     $expected = array('one' => 123, 'two' => 321, 'foo' => array('int' => 123, 'foo' => 'bar', 'bar' => 'foo'));
     $this->assertEquals(sugarArrayMergeRecursive($foo, $bar), $expected);
     // insure that internal functions can't duplicate behavior
     $this->assertNotEquals(array_merge($foo, $bar), $expected);
     $this->assertNotEquals(array_merge_recursive($foo, $bar), $expected);
 }
Exemplo n.º 2
0
 function handleOverride($fromParseLoggerSettings = false)
 {
     global $sugar_config, $sugar_version;
     $sc = SugarConfig::getInstance();
     $overrideArray = $this->readOverride();
     $this->previous_sugar_override_config_array = $overrideArray;
     $diffArray = deepArrayDiff($this->config, $sugar_config);
     $overrideArray = sugarArrayMergeRecursive($overrideArray, $diffArray);
     // To remember checkbox state
     if (!$this->useAuthenticationClass && !$fromParseLoggerSettings) {
         if (isset($overrideArray['authenticationClass']) && $overrideArray['authenticationClass'] == 'SAMLAuthenticate') {
             unset($overrideArray['authenticationClass']);
         }
     }
     $overideString = "<?php\n/***CONFIGURATOR***/\n";
     sugar_cache_put('sugar_config', $this->config);
     $GLOBALS['sugar_config'] = $this->config;
     //print_r($overrideArray);
     //Bug#53013: Clean the tpl cache if action menu style has been changed.
     if (isset($overrideArray['enable_action_menu']) && (!isset($this->previous_sugar_override_config_array['enable_action_menu']) || $overrideArray['enable_action_menu'] != $this->previous_sugar_override_config_array['enable_action_menu'])) {
         require_once 'modules/Administration/QuickRepairAndRebuild.php';
         $repair = new RepairAndClear();
         $repair->module_list = array();
         $repair->clearTpls();
     }
     foreach ($overrideArray as $key => $val) {
         if (in_array($key, $this->allow_undefined) || isset($sugar_config[$key])) {
             if (strcmp("{$val}", 'true') == 0) {
                 $val = true;
                 $this->config[$key] = $val;
             }
             if (strcmp("{$val}", 'false') == 0) {
                 $val = false;
                 $this->config[$key] = false;
             }
         }
         $overideString .= override_value_to_string_recursive2('sugar_config', $key, $val);
     }
     $overideString .= '/***CONFIGURATOR***/';
     $this->saveOverride($overideString);
     if (isset($this->config['logger']['level']) && $this->logger) {
         $this->logger->setLevel($this->config['logger']['level']);
     }
 }
Exemplo n.º 3
0
 function handleOverride($fromParseLoggerSettings = false)
 {
     global $sugar_config, $sugar_version;
     $sc = SugarConfig::getInstance();
     $overrideArray = $this->readOverride();
     $this->previous_sugar_override_config_array = $overrideArray;
     $diffArray = deepArrayDiff($this->config, $sugar_config);
     $overrideArray = sugarArrayMergeRecursive($overrideArray, $diffArray);
     // To remember checkbox state
     if (!$this->useAuthenticationClass && !$fromParseLoggerSettings) {
         if (isset($overrideArray['authenticationClass']) && $overrideArray['authenticationClass'] == 'SAMLAuthenticate') {
             unset($overrideArray['authenticationClass']);
         }
     }
     $overideString = "<?php\n/***CONFIGURATOR***/\n";
     sugar_cache_put('sugar_config', $this->config);
     $GLOBALS['sugar_config'] = $this->config;
     //print_r($overrideArray);
     foreach ($overrideArray as $key => $val) {
         if (in_array($key, $this->allow_undefined) || isset($sugar_config[$key])) {
             if (strcmp("{$val}", 'true') == 0) {
                 $val = true;
                 $this->config[$key] = $val;
             }
             if (strcmp("{$val}", 'false') == 0) {
                 $val = false;
                 $this->config[$key] = false;
             }
         }
         $overideString .= override_value_to_string_recursive2('sugar_config', $key, $val);
     }
     $overideString .= '/***CONFIGURATOR***/';
     $this->saveOverride($overideString);
     if (isset($this->config['logger']['level']) && $this->logger) {
         $this->logger->setLevel($this->config['logger']['level']);
     }
 }
Exemplo n.º 4
0
/**
 * Similiar to sugarArrayMerge except arrays of N depth are merged.
 *
 * @param array gimp the array whose values will be overloaded
 * @param array dom the array whose values will pwn the gimp's
 * @return array beaten gimp
 */
function sugarArrayMergeRecursive($gimp, $dom)
{
    if (is_array($gimp) && is_array($dom)) {
        foreach ($dom as $domKey => $domVal) {
            if (array_key_exists($domKey, $gimp)) {
                if (is_array($domVal) && is_array($gimp[$domKey])) {
                    $gimp[$domKey] = sugarArrayMergeRecursive($gimp[$domKey], $domVal);
                } else {
                    $gimp[$domKey] = $domVal;
                }
            } else {
                $gimp[$domKey] = $domVal;
            }
        }
    } elseif (is_array($dom)) {
        return $dom;
    }
    return $gimp;
}
Exemplo n.º 5
0
 /**
  * Given a module, search all of the specified locations, and any others as specified
  * in order to refresh the cache file
  *
  * @param string $module the given module we want to load the vardefs for
  * @param string $lang the given language we wish to load
  * @param array $additional_search_paths an array which allows a consumer to pass in additional vardef locations to search
  */
 function refreshLanguage($module, $lang, $loaded_mod_strings = array(), $additional_search_paths = null)
 {
     // Some of the vardefs do not correctly define dictionary as global.  Declare it first.
     $lang_paths = array('modules/' . $module . '/language/' . $lang . '.lang.php', 'modules/' . $module . '/language/' . $lang . '.lang.override.php', 'custom/modules/' . $module . '/Ext/Language/' . $lang . '.lang.ext.php', 'custom/modules/' . $module . '/language/' . $lang . '.lang.php');
     #27023, if this module template language file was not attached , get the template from this module vardef cache file if exsits and load the template language files.
     static $createdModules;
     if (empty($createdModules[$module]) && isset($GLOBALS['beanList'][$module])) {
         $object = $GLOBALS['beanList'][$module];
         if ($object == 'aCase') {
             $object = 'Case';
         }
         if (!empty($GLOBALS["dictionary"]["{$object}"]["templates"])) {
             $templates = $GLOBALS["dictionary"]["{$object}"]["templates"];
             $loaded_mod_strings = LanguageManager::loadTemplateLanguage($module, $templates, $lang, $loaded_mod_strings);
             $createdModules[$module] = true;
         }
     }
     //end of fix #27023
     // Add in additional search paths if they were provided.
     if (!empty($additional_search_paths) && is_array($additional_search_paths)) {
         $lang_paths = array_merge($lang_paths, $additional_search_paths);
     }
     //search a predefined set of locations for the vardef files
     foreach ($lang_paths as $path) {
         if (file_exists($path)) {
             require $path;
             if (!empty($mod_strings)) {
                 if (function_exists('sugarArrayMergeRecursive')) {
                     $loaded_mod_strings = sugarArrayMergeRecursive($loaded_mod_strings, $mod_strings);
                 } else {
                     $loaded_mod_strings = sugarLangArrayMerge($loaded_mod_strings, $mod_strings);
                 }
             }
         }
     }
     //great! now that we have loaded all of our vardefs.
     //let's go save them to the cache file.
     if (!empty($loaded_mod_strings)) {
         LanguageManager::saveCache($module, $lang, $loaded_mod_strings);
     }
 }
Exemplo n.º 6
0
 /**
  * Compare 3 configs and generate one to be saved to the config.php file.
  *
  * @param array $old  : the old configs from "config.php" before upgrade.
  * @param array $over : the override configs from "config_override.php".
  * @param array $new  : the new configs generated during the upgrade.
  *
  * @return array the array to be saved.
  */
 public function genConfigs($old, $over, $new)
 {
     //remove the override configs from the new configs
     $diffArray = deepArrayDiff($new, $over);
     $saveArray = sugarArrayMergeRecursive($old, $diffArray);
     return $saveArray;
 }
 /**
  *
  * Read default and specific index settings from config
  * @param string  $indexName
  * @param array   $params
  * @param boolean $addDefaults
  * @return array
  */
 protected function getIndexSetting($indexName, $params = array(), $addDefaults = true)
 {
     $indexSettings = array('index' => array('analysis' => array('analyzer' => array('core_email_lowercase' => array('type' => 'custom', 'tokenizer' => 'uax_url_email', 'filter' => array('lowercase'))))));
     if (empty($params['index_settings']) || !is_array($params['index_settings'])) {
         return $indexSettings;
     }
     $settings = $params['index_settings'];
     if ($addDefaults && isset($settings['default']) && is_array($settings['default'])) {
         $indexSettings = sugarArrayMergeRecursive($indexSettings, $settings['default']);
     }
     if (isset($settings[$indexName]) && is_array($settings[$indexName])) {
         $indexSettings = sugarArrayMergeRecursive($indexSettings, $settings[$indexName]);
     }
     $GLOBALS['log']->info("Index settings for {$indexName} -> " . var_export($indexSettings, true));
     return $indexSettings;
 }
Exemplo n.º 8
0
 /**
  * Given a module, search all of the specified locations, and any others as specified
  * in order to refresh the cache file
  *
  * @param string $module the given module we want to load the vardefs for
  * @param string $lang the given language we wish to load
  * @param array $additional_search_paths an array which allows a consumer to pass in additional vardef locations to search
  */
 public static function refreshLanguage($module, $lang, $loaded_mod_strings = array(), $additional_search_paths = null)
 {
     // Some of the vardefs do not correctly define dictionary as global.  Declare it first.
     $lang_paths = self::getModuleLanguageFilePaths($module, $lang);
     $object = BeanFactory::getObjectName($module);
     if ($object && !empty($GLOBALS['dictionary'][$object]['templates'])) {
         $templates = $GLOBALS['dictionary'][$object]['templates'];
         $loaded_mod_strings = LanguageManager::loadTemplateLanguage($module, $templates, $lang, $loaded_mod_strings);
     }
     // Add in additional search paths if they were provided.
     if (!empty($additional_search_paths) && is_array($additional_search_paths)) {
         $lang_paths = array_merge($lang_paths, $additional_search_paths);
     }
     //search a predefined set of locations for the vardef files
     foreach (SugarAutoLoader::existing($lang_paths) as $path) {
         require $path;
         if (!empty($mod_strings)) {
             if (function_exists('sugarArrayMergeRecursive')) {
                 $loaded_mod_strings = sugarArrayMergeRecursive($loaded_mod_strings, $mod_strings);
             } else {
                 $loaded_mod_strings = sugarLangArrayMerge($loaded_mod_strings, $mod_strings);
             }
         }
     }
     //great! now that we have loaded all of our vardefs.
     //let's go save them to the cache file.
     if (!empty($loaded_mod_strings)) {
         LanguageManager::saveCache($module, $lang, $loaded_mod_strings);
     }
 }