diff --git a/application/Espo/Core/Application.php b/application/Espo/Core/Application.php index eff2672d6f..daaeb9f98a 100644 --- a/application/Espo/Core/Application.php +++ b/application/Espo/Core/Application.php @@ -98,13 +98,18 @@ class Application $cronManager->run(); } - public function isInstalled() + public function isInstalled($useRedirect = true) { - $configFile = $this->getContainer()->get('config')->get('configPath'); - if (!file_exists($configFile)) { + $configFile = $this->getContainer()->get('config')->get('configPath'); + + $result = file_exists($configFile) ? true : false; + + if ($useRedirect && !$result) { header("Location: install/"); exit; } + + return $result; } protected function routeHooks() diff --git a/application/Espo/Core/Utils/Config.php b/application/Espo/Core/Utils/Config.php index 424a7a1034..b56b04f917 100644 --- a/application/Espo/Core/Utils/Config.php +++ b/application/Espo/Core/Utils/Config.php @@ -76,6 +76,10 @@ class Config */ public function set($name, $value='') { + if (is_array($name)) { + return $this->setArray($name); + } + if (Json::isJSON($value)) { $value= Json::decode($value); } @@ -94,7 +98,7 @@ class Config * @param array $values * @return bool */ - public function setArray($values) + protected function setArray($values) { if (Json::isJSON($values)) { $values = Json::decode($values); @@ -162,10 +166,8 @@ class Config * @param $isAdmin * @return bool */ - //HERE public function setData($data, $isAdmin=false) { - $restrictItems = $this->getRestrictItems($isAdmin); $values= array(); diff --git a/application/Espo/Core/Utils/Json.php b/application/Espo/Core/Utils/Json.php index 5e19e193db..ddf41bebe8 100644 --- a/application/Espo/Core/Utils/Json.php +++ b/application/Espo/Core/Utils/Json.php @@ -14,10 +14,14 @@ class Json */ public static function encode($value, $options = 0, $depth = 512) { - if(version_compare(phpversion(), '5.5.0', '>=')) { + if ($options == 0) { + $options = JSON_PRETTY_PRINT; + } + + if (version_compare(phpversion(), '5.5.0', '>=')) { $json = json_encode($value, $options, $depth); } - elseif(version_compare(phpversion(), '5.3.0', '>=')) { + elseif (version_compare(phpversion(), '5.3.0', '>=')) { /*Check if options are supported for this version of PHP*/ if (is_int($options)) { $json = json_encode($value, $options); diff --git a/application/Espo/Core/Utils/Metadata.php b/application/Espo/Core/Utils/Metadata.php index 98822724dc..d1d35d330c 100644 --- a/application/Espo/Core/Utils/Metadata.php +++ b/application/Espo/Core/Utils/Metadata.php @@ -202,7 +202,7 @@ class Metadata $path = str_replace('{*}', $moduleName, $this->paths['modulePath']); } - $result= $this->getFileManager()->putContents(array($path, $type, $scope.'.json'), $data); + $result= $this->getFileManager()->mergeContents(array($path, $type, $scope.'.json'), $data, true); return $result; } diff --git a/tests/Espo/Core/Utils/ConfigTest.php b/tests/Espo/Core/Utils/ConfigTest.php index 31e9931d28..00d61feafb 100644 --- a/tests/Espo/Core/Utils/ConfigTest.php +++ b/tests/Espo/Core/Utils/ConfigTest.php @@ -67,4 +67,25 @@ class ConfigTest extends \PHPUnit_Framework_TestCase $this->assertTrue($this->object->set($setKey, 'Another Wrong Value')); } + function testSetArray() + { + $this->reflection->setProperty('defaultConfigPath', 'tests/testData/Utils/Config/defaultConfigArray.php'); + + $values = array( + 'testOption' => 'Test', + 'testOption2' => 'Test2', + ); + + $this->assertTrue($this->object->set($values)); + $this->assertEquals('Test', $this->object->get('testOption')); + $this->assertEquals('Test2', $this->object->get('testOption2')); + + $wrongArray = array( + 'testOption' => 'Another Wrong Value', + ); + $this->assertTrue($this->object->set($wrongArray)); + + $this->reflection->setProperty('defaultConfigPath', $this->defaultConfigPath); + } + } \ No newline at end of file diff --git a/tests/testData/Utils/Config/config.php b/tests/testData/Utils/Config/config.php index e79daf19ff..c2460e7f50 100644 --- a/tests/testData/Utils/Config/config.php +++ b/tests/testData/Utils/Config/config.php @@ -31,6 +31,7 @@ return array ( 1 => 'EUR', ), 'testOption' => 'Another Wrong Value', + 'testOption2' => 'Test2', ); ?> \ No newline at end of file diff --git a/tests/testData/Utils/Config/defaultConfig.php b/tests/testData/Utils/Config/defaultConfig.php index 36739b4ac8..005191cd17 100644 --- a/tests/testData/Utils/Config/defaultConfig.php +++ b/tests/testData/Utils/Config/defaultConfig.php @@ -1,7 +1,7 @@ 'tests/testData/Utils/Config/config.php', + 'configPath' => 'tests/testData/Utils/Config/testArray.php', 'dateFormat' => 'MM/DD/YYYY', 'timeFormat' => 'HH:mm', diff --git a/tests/testData/Utils/Config/defaultConfigArray.php b/tests/testData/Utils/Config/defaultConfigArray.php new file mode 100644 index 0000000000..36739b4ac8 --- /dev/null +++ b/tests/testData/Utils/Config/defaultConfigArray.php @@ -0,0 +1,56 @@ + 'tests/testData/Utils/Config/config.php', + + 'dateFormat' => 'MM/DD/YYYY', + 'timeFormat' => 'HH:mm', + + 'cron' => array( + 'maxJobNumber' => 15, /*Max number of jobs per one execution*/ + 'jobPeriod' => 7800, /*Period for jobs, ex. if cron executed at 15:35, it will execute all pending jobs for times from 14:05 to 15:35*/ + 'minExecutionTime' => 50, /*to avoid too frequency execution*/ + ), + + 'systemUser' => array( + 'id' => 'system', + 'userName' => 'system', + 'firstName' => '', + 'lastName' => 'System', + ), + + 'crud' => array( + 'get' => 'read', + 'post' => 'create', + 'put' => 'update', + 'patch' => 'patch', + 'delete' => 'delete', + ), + 'systemItems' => + array ( + 'systemItems', + 'adminItems', + 'configPath', + 'cachePath', + 'database', + 'customPath', + 'defaultsPath', + 'crud', + ), + 'adminItems' => + array ( + 'defaultPermissions', + 'logger', + 'devMode', + ), + 'currency' => + array( + 'base' => 'USD', + 'rate' => array( + 'EUR' => 1.37, + 'GBP' => 1.67, + ), + ), +); + +?> diff --git a/tests/testData/Utils/Config/testArray.php b/tests/testData/Utils/Config/testArray.php new file mode 100644 index 0000000000..b4d1e6bc55 --- /dev/null +++ b/tests/testData/Utils/Config/testArray.php @@ -0,0 +1,7 @@ + 'Another Wrong Value', +); + +?> \ No newline at end of file