function handleOverride() { 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 = sugarArrayMerge($overrideArray, $diffArray); $overideString = "<?php\n/***CONFIGURATOR***/\n"; sugar_cache_put('sugar_config', $this->config); $GLOBALS['sugar_config'] = $this->config; 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']); } }
/** * @ticket 24067 */ public function testdeepArrayDiffWithBooleanFalse() { $array1 = array('value1' => true, 'value2' => false, 'value3' => 'yummy'); $array2 = array('value1' => true, 'value2' => true, 'value3' => 'yummy'); $diffs = deepArrayDiff($array1, $array2); $this->assertEquals($diffs['value2'], false); $this->assertFalse(isset($diffs['value1'])); $this->assertFalse(isset($diffs['value3'])); $diffs = deepArrayDiff($array2, $array1); $this->assertEquals($diffs['value2'], true); $this->assertFalse(isset($diffs['value1'])); $this->assertFalse(isset($diffs['value3'])); }
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']); } }
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']); } }
/** * This function returns an array of all the key=>value pairs in $array1 * that are wither not present, or different in $array2. * If a key exists in $array2 but not $array1, it will not be reported. * Values which are arrays are traced further and reported only if thier is a difference * in one or more of thier children. * * @param array $array1, the array which contains all the key=>values you wish to check againts * @param array $array2, the array which * @param array $allowEmpty, will return the value if it is empty in $array1 and not in $array2, * otherwise empty values in $array1 are ignored. * @return array containing the differences between the two arrays */ function deepArrayDiff($array1, $array2, $allowEmpty = false) { $diff = array(); foreach ($array1 as $key => $value) { if (is_array($value)) { if ((!isset($array2[$key]) || !is_array($array2[$key])) && (isset($value) || $allowEmpty)) { $diff[$key] = $value; } else { $value = deepArrayDiff($array1[$key], $array2[$key], $allowEmpty); if (!empty($value) || $allowEmpty) { $diff[$key] = $value; } } } else { if ((!isset($array2[$key]) || $value != $array2[$key]) && (isset($value) || $allowEmpty)) { $diff[$key] = $value; } } } return $diff; }
/** * 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 config & config override, and return old config and their difference * @return array[old config, difference in configs] */ protected function readOverride() { $sugar_config = array(); if (is_readable('config.php')) { include 'config.php'; } $old_config = $sugar_config; if (file_exists('config_override.php')) { if (!is_readable('config_override.php')) { $GLOBALS['log']->fatal("Unable to read the config_override.php file. Check the file permissions"); } else { include 'config_override.php'; } } return array($old_config, deepArrayDiff($sugar_config, $old_config)); }
public function testdeepArrayDiff() { //execute the method and test if it returns expected values //same simple arrays $tempArray1 = array('Key1' => 'value1', 'Key2' => 'value2'); $tempArray2 = array('Key1' => 'value1', 'Key2' => 'value2'); $expected = array(); $actual = deepArrayDiff($tempArray1, $tempArray2); $this->assertSame($actual, $expected); //different simple arrays $tempArray1 = array('Key1' => 'value1', 'Key2' => 'value2'); $tempArray2 = array('Key1' => 'value1', 'Key2' => 'value3'); $expected = array('Key2' => 'value2'); $actual = deepArrayDiff($tempArray1, $tempArray2); $this->assertSame($actual, $expected); //same complex arrays $tempArray1 = array('Key1' => array('Key2' => 'value2', 'Key3' => 'value3')); $tempArray2 = array('Key1' => array('Key2' => 'value2', 'Key3' => 'value3')); $expected = array(); $actual = deepArrayDiff($tempArray1, $tempArray2); $this->assertSame($actual, $expected); //complex arrays with different root node $tempArray1 = array('Key1' => array('Key2' => 'value2', 'Key3' => 'value3')); $tempArray2 = array('Key2' => array('Key2' => 'value2', 'Key3' => 'value3')); $expected = array('Key1' => array('Key2' => 'value2', 'Key3' => 'value3')); $actual = deepArrayDiff($tempArray1, $tempArray2); $this->assertSame($actual, $expected); //complex arrays with different child node $tempArray1 = array('Key1' => array('Key2' => 'value2', 'Key3' => 'value3')); $tempArray2 = array('Key1' => array('Key2' => 'value2', 'Key4' => 'value4')); $expected = array('Key1' => array('Key3' => 'value3')); $actual = deepArrayDiff($tempArray1, $tempArray2); $this->assertSame($actual, $expected); }