function populateFromPost() { $sugarConfig = SugarConfig::getInstance(); foreach ($_POST as $key => $value) { if ($key == "logger_file_ext") { $trim_value = preg_replace('/.*\\.([^\\.]+)$/', '\\1', $value); if (in_array($trim_value, $this->config['upload_badext'])) { $GLOBALS['log']->security("Invalid log file extension: trying to use invalid file extension '{$value}'."); continue; } } if (isset($this->config[$key]) || in_array($key, $this->allow_undefined)) { if (strcmp("{$value}", 'true') == 0) { $value = true; } if (strcmp("{$value}", 'false') == 0) { $value = false; } $this->config[$key] = $value; } else { $v = $sugarConfig->get(str_replace('_', '.', $key)); if ($v !== null) { setDeepArrayValue($this->config, $key, $value); } } } }
/** * @params : none * @return : An array of logger configuration properties including log size, file extensions etc. See SugarLogger for more details. * Parses the old logger settings from the log4php.properties files. * */ function parseLoggerSettings() { if (!function_exists('setDeepArrayValue')) { require 'include/utils/array_utils.php'; } if (file_exists('log4php.properties')) { $fileContent = file_get_contents('log4php.properties'); $old_props = explode('\\n', $fileContent); $new_props = array(); $key_names = array(); foreach ($old_props as $value) { if (!empty($value) && !preg_match("/^\\/\\//", $value)) { $temp = explode("=", $value); $property = isset($temp[1]) ? $temp[1] : array(); if (preg_match("/log4php.appender.A2.MaxFileSize=/", $value)) { setDeepArrayValue($this->config, 'logger_file_maxSize', rtrim($property)); } elseif (preg_match("/log4php.appender.A2.File=/", $value)) { $ext = preg_split("/\\./", $property); if (preg_match("/^\\./", $property)) { //begins with . setDeepArrayValue($this->config, 'logger_file_ext', isset($ext[2]) ? '.' . rtrim($ext[2]) : '.log'); setDeepArrayValue($this->config, 'logger_file_name', rtrim("." . $ext[1])); } else { setDeepArrayValue($this->config, 'logger_file_ext', isset($ext[1]) ? '.' . rtrim($ext[1]) : '.log'); setDeepArrayValue($this->config, 'logger_file_name', rtrim($ext[0])); } } elseif (preg_match("/log4php.appender.A2.layout.DateFormat=/", $value)) { setDeepArrayValue($this->config, 'logger_file_dateFormat', trim(rtrim($property), '""')); } elseif (preg_match("/log4php.rootLogger=/", $value)) { $property = explode(",", $property); setDeepArrayValue($this->config, 'logger_level', rtrim($property[0])); } } } setDeepArrayValue($this->config, 'logger_file_maxLogs', 10); setDeepArrayValue($this->config, 'logger_file_suffix', "%m_%Y"); $this->handleOverride(); unlink('log4php.properties'); $GLOBALS['sugar_config'] = $this->config; //load the rest of the sugar_config settings. require_once 'include/SugarLogger/SugarLogger.php'; //$logger = new SugarLogger(); //this will create the log file. } if (!isset($this->config['logger']) || empty($this->config['logger'])) { $this->config['logger'] = array('file' => array('ext' => '.log', 'name' => 'sugarcrm', 'dateFormat' => '%c', 'maxSize' => '10MB', 'maxLogs' => 10, 'suffix' => ''), 'level' => 'fatal'); } $this->handleOverride(true); }
/** * Recursivly set a value in an array, creating sub arrays as necessary * * @param unknown_type $array * @param unknown_type $key */ function setDeepArrayValue(&$array, $key, $value) { //if _ is at position zero, that is invalid. if (strrpos($key, "_")) { list($key, $remkey) = explode('_', $key, 2); if (!isset($array[$key]) || !is_array($array[$key])) { $array[$key] = array(); } setDeepArrayValue($array[$key], $remkey, $value); } else { $array[$key] = $value; } }
public function test_setDeepArrayValue() { $arrayActualSimple = array(1 => 'a'); setDeepArrayValue($arrayActualSimple, 1, 'b'); $arrayExpectedSimple = array(1 => 'b'); $this->assertEquals($arrayExpectedSimple, $arrayActualSimple); }
/** * Set value to current instance with key sliced by "/" * * @param mixed $value * @param string $deepKey * @return BaseStorage */ public function setDeepValue($deepKey, $value) { setDeepArrayValue($this->_data, $value, $deepKey); return $this; }
public function testsetDeepArrayValue() { //execute the method and test if it returns expected values //add to existing array $tempArray = array('Key1' => array('Key2' => 'value2', 'Key3' => 'value3')); $expected = array('Key1' => array('Key2' => 'value2', 'Key3' => 'value3'), 'key4' => 'value4'); setDeepArrayValue($tempArray, 'key4', 'value4'); $this->assertSame($tempArray, $expected); //add to empty array $tempArray = array(); $expected = array('key1' => array('key2' => array('key3' => 'value3'))); setDeepArrayValue($tempArray, 'key1_key2_key3', 'value3'); //var_dump($tempArray); $this->assertSame($tempArray, $expected); }