diff --git a/application/Espo/Core/Utils/Config.php b/application/Espo/Core/Utils/Config.php index ddc3bb62a7..428944528d 100644 --- a/application/Espo/Core/Utils/Config.php +++ b/application/Espo/Core/Utils/Config.php @@ -32,6 +32,8 @@ class Config */ private $defaultConfigPath = 'application/Espo/Core/defaults/config.php'; + private $systemConfigPath = 'application/Espo/Core/defaults/systemConfig.php'; + protected $configPath = 'data/config.php'; private $cacheTimestamp = 'cacheTimestamp'; @@ -153,6 +155,9 @@ class Config $this->configData = $this->getFileManager()->getContents($configPath); + $systemConfig = $this->getFileManager()->getContents($this->systemConfigPath); + $this->configData = Util::merge($systemConfig, $this->configData); + return $this->configData; } diff --git a/application/Espo/Core/defaults/config.php b/application/Espo/Core/defaults/config.php index ff38f7d005..0f8c3d26e5 100644 --- a/application/Espo/Core/defaults/config.php +++ b/application/Espo/Core/defaults/config.php @@ -71,18 +71,6 @@ return array ( 'isRotate' => true, /** rotate log files every day */ 'maxRotateFiles' => 30, /** max number of rotate files */ ), - 'defaultPermissions' => - array ( - 'dir' => '0775', - 'file' => '0664', - 'user' => '', - 'group' => '', - ), - '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 **/ - ), 'globalSearchEntityList' => array ( 0 => 'Account', @@ -93,46 +81,6 @@ return array ( ), "tabList" => array("Account", "Contact", "Lead", "Opportunity", "Calendar", "Meeting", "Call", "Task", "Case", "Prospect", "Email"), "quickCreateList" => array("Account", "Contact", "Lead", "Opportunity", "Meeting", "Call", "Task", "Case", "Prospect"), - 'crud' => array( - 'get' => 'read', - 'post' => 'create', - 'put' => 'update', - 'patch' => 'patch', - 'delete' => 'delete', - ), - 'systemUser' => array( - 'id' => 'system', - 'userName' => 'system', - 'firstName' => '', - 'lastName' => 'System', - ), - 'systemItems' => - array ( - 'systemItems', - 'adminItems', - 'configPath', - 'cachePath', - 'database', - 'crud', - 'logger', - 'isInstalled', - 'defaultPermissions', - 'systemUser', - ), - 'adminItems' => - array ( - 'devMode', - 'outboundEmailIsShared', - 'outboundEmailFromName', - 'outboundEmailFromAddress', - 'smtpServer', - 'smtpPort', - 'smtpAuth', - 'smtpSecurity', - 'smtpUsername', - 'smtpPassword', - 'cron', - ), 'isInstalled' => false, ); diff --git a/application/Espo/Core/defaults/systemConfig.php b/application/Espo/Core/defaults/systemConfig.php new file mode 100644 index 0000000000..ba67044450 --- /dev/null +++ b/application/Espo/Core/defaults/systemConfig.php @@ -0,0 +1,78 @@ + + array ( + 'dir' => '0775', + 'file' => '0664', + 'user' => '', + 'group' => '', + ), + '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 **/ + ), + 'crud' => array( + 'get' => 'read', + 'post' => 'create', + 'put' => 'update', + 'patch' => 'patch', + 'delete' => 'delete', + ), + 'systemUser' => array( + 'id' => 'system', + 'userName' => 'system', + 'firstName' => '', + 'lastName' => 'System', + ), + 'systemItems' => + array ( + 'systemItems', + 'adminItems', + 'configPath', + 'cachePath', + 'database', + 'crud', + 'logger', + 'isInstalled', + 'defaultPermissions', + 'systemUser', + ), + 'adminItems' => + array ( + 'devMode', + 'outboundEmailIsShared', + 'outboundEmailFromName', + 'outboundEmailFromAddress', + 'smtpServer', + 'smtpPort', + 'smtpAuth', + 'smtpSecurity', + 'smtpUsername', + 'smtpPassword', + 'cron', + ), + 'isInstalled' => false, +); + diff --git a/tests/Espo/Core/Utils/ConfigTest.php b/tests/Espo/Core/Utils/ConfigTest.php index 8602763d97..bfce8f7909 100644 --- a/tests/Espo/Core/Utils/ConfigTest.php +++ b/tests/Espo/Core/Utils/ConfigTest.php @@ -13,6 +13,8 @@ class ConfigTest extends \PHPUnit_Framework_TestCase protected $configPath = 'tests/testData/Utils/Config/config.php'; + protected $systemConfigPath = 'tests/testData/Utils/Config/systemConfig.php'; + protected function setUp() { $this->objects['fileManager'] = new \Espo\Core\Utils\File\Manager(); @@ -20,7 +22,9 @@ class ConfigTest extends \PHPUnit_Framework_TestCase $this->object = new \Espo\Core\Utils\Config($this->objects['fileManager']); $this->reflection = new ReflectionHelper($this->object); + $this->reflection->setProperty('configPath', $this->configPath); + $this->reflection->setProperty('systemConfigPath', $this->systemConfigPath); } protected function tearDown() @@ -29,14 +33,14 @@ class ConfigTest extends \PHPUnit_Framework_TestCase } - function testLoadConfig() + public function testLoadConfig() { $this->assertArrayHasKey('database', $this->reflection->invokeMethod('loadConfig', array())); $this->assertArrayHasKey('dateFormat', $this->reflection->invokeMethod('loadConfig', array())); } - function testGet() + public function testGet() { $result = array( 'driver' => 'pdo_mysql', @@ -58,7 +62,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase } - function testSet() + public function testSet() { $setKey= 'testOption'; $setValue= 'Test'; @@ -69,7 +73,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase $this->assertTrue($this->object->set($setKey, 'Another Wrong Value')); } - function testSetArray() + public function testSetArray() { $values = array( 'testOption' => 'Test', @@ -86,4 +90,16 @@ class ConfigTest extends \PHPUnit_Framework_TestCase $this->assertTrue($this->object->set($wrongArray)); } + public function testSystemConfigMerge() + { + $configDataWithoutSystem = $this->objects['fileManager']->getContents($this->configPath); + $this->assertArrayNotHasKey('systemItems', $configDataWithoutSystem); + $this->assertArrayNotHasKey('adminItems', $configDataWithoutSystem); + + $configData = $this->reflection->invokeMethod('loadConfig', array()); + + $this->assertArrayHasKey('systemItems', $configData); + $this->assertArrayHasKey('adminItems', $configData); + } + } \ No newline at end of file diff --git a/tests/testData/Utils/Config/config.php b/tests/testData/Utils/Config/config.php index 2aae4eb795..d9bb88df2e 100644 --- a/tests/testData/Utils/Config/config.php +++ b/tests/testData/Utils/Config/config.php @@ -116,35 +116,8 @@ return array ( 'firstName' => '', 'lastName' => 'System', ), - 'systemItems' => - array ( - 0 => 'systemItems', - 1 => 'adminItems', - 2 => 'configPath', - 3 => 'cachePath', - 4 => 'database', - 5 => 'crud', - 6 => 'logger', - 7 => 'isInstalled', - 8 => 'defaultPermissions', - 9 => 'systemUser', - ), - 'adminItems' => - array ( - 0 => 'devMode', - 1 => 'outboundEmailIsShared', - 2 => 'outboundEmailFromName', - 3 => 'outboundEmailFromAddress', - 4 => 'smtpServer', - 5 => 'smtpPort', - 6 => 'smtpAuth', - 7 => 'smtpSecurity', - 8 => 'smtpUsername', - 9 => 'smtpPassword', - 10 => 'cron', - ), 'isInstalled' => true, - 'cacheTimestamp' => 1400160414, + 'cacheTimestamp' => 1401873639, 'testOption' => 'Another Wrong Value', 'testOption2' => 'Test2', ); diff --git a/tests/testData/Utils/Config/systemConfig.php b/tests/testData/Utils/Config/systemConfig.php new file mode 100644 index 0000000000..ba67044450 --- /dev/null +++ b/tests/testData/Utils/Config/systemConfig.php @@ -0,0 +1,78 @@ + + array ( + 'dir' => '0775', + 'file' => '0664', + 'user' => '', + 'group' => '', + ), + '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 **/ + ), + 'crud' => array( + 'get' => 'read', + 'post' => 'create', + 'put' => 'update', + 'patch' => 'patch', + 'delete' => 'delete', + ), + 'systemUser' => array( + 'id' => 'system', + 'userName' => 'system', + 'firstName' => '', + 'lastName' => 'System', + ), + 'systemItems' => + array ( + 'systemItems', + 'adminItems', + 'configPath', + 'cachePath', + 'database', + 'crud', + 'logger', + 'isInstalled', + 'defaultPermissions', + 'systemUser', + ), + 'adminItems' => + array ( + 'devMode', + 'outboundEmailIsShared', + 'outboundEmailFromName', + 'outboundEmailFromAddress', + 'smtpServer', + 'smtpPort', + 'smtpAuth', + 'smtpSecurity', + 'smtpUsername', + 'smtpPassword', + 'cron', + ), + 'isInstalled' => false, +); +