diff --git a/application/Espo/Controllers/Settings.php b/application/Espo/Controllers/Settings.php
index e564a0f43f..44d39a3133 100644
--- a/application/Espo/Controllers/Settings.php
+++ b/application/Espo/Controllers/Settings.php
@@ -30,9 +30,9 @@ class Settings extends \Espo\Core\Controllers\Base
protected function getConfigData()
{
$data = $this->getConfig()->getData($this->getUser()->isAdmin());
-
+
$fieldDefs = $this->getMetadata()->get('entityDefs.Settings.fields');
-
+
foreach ($fieldDefs as $field => $d) {
if ($d['type'] == 'password') {
unset($data[$field]);
@@ -40,7 +40,7 @@ class Settings extends \Espo\Core\Controllers\Base
}
return $data;
}
-
+
public function actionRead($params, $data)
{
return $this->getConfigData();
@@ -52,12 +52,13 @@ class Settings extends \Espo\Core\Controllers\Base
}
public function actionPatch($params, $data)
- {
+ {
if (!$this->getUser()->isAdmin()) {
throw new Forbidden();
}
-
- $result = $this->getConfig()->setData($data, $this->getUser()->isAdmin());
+
+ $this->getConfig()->setData($data, $this->getUser()->isAdmin());
+ $result = $this->getConfig()->save();
if ($result === false) {
throw new Error('Cannot save settings');
}
diff --git a/application/Espo/Core/Upgrades/Base.php b/application/Espo/Core/Upgrades/Base.php
index 2da72f5a15..b8687031c9 100644
--- a/application/Espo/Core/Upgrades/Base.php
+++ b/application/Espo/Core/Upgrades/Base.php
@@ -375,6 +375,9 @@ abstract class Base
$manifest = $this->getManifest();
$res = $this->getConfig()->set('version', $manifest['version']);
+ if (method_exists($this->getConfig(), 'save')) {
+ $res = $this->getConfig()->save();
+ }
$res &= $this->getContainer()->get('dataManager')->rebuild();
return $res;
diff --git a/application/Espo/Core/Utils/Config.php b/application/Espo/Core/Utils/Config.php
index 428944528d..40f6fba2df 100644
--- a/application/Espo/Core/Utils/Config.php
+++ b/application/Espo/Core/Utils/Config.php
@@ -53,7 +53,9 @@ class Config
* @access private
* @var array
*/
- private $configData;
+ private $data;
+
+ private $changedData = array();
private $fileManager;
@@ -109,28 +111,25 @@ class Config
$name = array($name => $value);
}
- return $this->setArray($name);
+ foreach ($name as $key => $value) {
+ $this->data[$key] = $value;
+ $this->changedData[$key] = $value;
+ }
}
-
- /**
- * Set options from array
- *
- * @param array $values
- * @return bool
- */
- protected function setArray($values)
+ public function save()
{
- if (!is_array($values)) {
- return false;
- }
+ $values = $this->changedData;
if (!isset($values[$this->cacheTimestamp])) {
$values = array_merge($this->updateCacheTimestamp(true), $values);
}
$result = $this->getFileManager()->mergeContentsPHP($this->configPath, $values, true);
- $this->loadConfig(true);
+ if ($result) {
+ $this->changedData = array();
+ $this->loadConfig(true);
+ }
return $result;
}
@@ -147,18 +146,18 @@ class Config
*/
protected function loadConfig($reload = false)
{
- if (!$reload && isset($this->configData) && !empty($this->configData)) {
- return $this->configData;
+ if (!$reload && isset($this->data) && !empty($this->data)) {
+ return $this->data;
}
$configPath = file_exists($this->configPath) ? $this->configPath : $this->defaultConfigPath;
- $this->configData = $this->getFileManager()->getContents($configPath);
+ $this->data = $this->getFileManager()->getContents($configPath);
$systemConfig = $this->getFileManager()->getContents($this->systemConfigPath);
- $this->configData = Util::merge($systemConfig, $this->configData);
+ $this->data = Util::merge($systemConfig, $this->data);
- return $this->configData;
+ return $this->data;
}
@@ -170,9 +169,9 @@ class Config
*/
public function getData($isAdmin = false)
{
- $configData = $this->loadConfig();
+ $data = $this->loadConfig();
- $restrictedConfig = $configData;
+ $restrictedConfig = $data;
foreach($this->getRestrictItems($isAdmin) as $name) {
if (isset($restrictedConfig[$name])) {
unset($restrictedConfig[$name]);
@@ -200,7 +199,7 @@ class Config
}
}
- return $this->setArray($values);
+ return $this->set($values);
}
/**
@@ -229,14 +228,14 @@ class Config
*/
protected function getRestrictItems($onlySystemItems = false)
{
- $configData = $this->loadConfig();
+ $data = $this->loadConfig();
if ($onlySystemItems) {
- return $configData['systemItems'];
+ return $data['systemItems'];
}
if (empty($this->adminItems)) {
- $this->adminItems= Util::merge($configData['systemItems'], $configData['adminItems']);
+ $this->adminItems= Util::merge($data['systemItems'], $data['adminItems']);
}
return $this->adminItems;
diff --git a/install/core/Installer.php b/install/core/Installer.php
index df7c3cb01a..b4987cf54e 100644
--- a/install/core/Installer.php
+++ b/install/core/Installer.php
@@ -65,6 +65,7 @@ class Installer
if (!file_exists($configPath)) {
$configData = $this->getConfig()->getDefaults();
$this->getConfig()->set($configData);
+ $this->getConfig()->save();
}
}
@@ -167,7 +168,8 @@ class Installer
{
$config = $this->app->getContainer()->get('config');
- $result = $config->set($data);
+ $config->set($data);
+ $result = $config->save();
return $result;
}
@@ -314,7 +316,8 @@ class Installer
public function setSuccess()
{
$config = $this->app->getContainer()->get('config');
- $result = $config->set('isInstalled', true);
+ $config->set('isInstalled', true);
+ $result = $config->save();
return $result;
}
diff --git a/install/core/SystemHelper.php b/install/core/SystemHelper.php
index 2ad316ea33..f9d8b5f42d 100644
--- a/install/core/SystemHelper.php
+++ b/install/core/SystemHelper.php
@@ -76,13 +76,13 @@ class SystemHelper extends \Espo\Core\Utils\System
return $result;
}
- public function checkDbConnection($hostName, $dbUserName, $dbUserPass, $dbName, $dbDriver = 'pdo_mysql')
+ public function checkDbConnection($hostName, $port ,$dbUserName, $dbUserPass, $dbName, $dbDriver = 'pdo_mysql')
{
$result['success'] = true;
switch ($dbDriver) {
case 'mysqli':
- $mysqli = new mysqli($hostName, $dbUserName, $dbUserPass, $dbName);
+ $mysqli = (empty($port)) ? new mysqli($hostName, $dbUserName, $dbUserPass, $dbName) : new mysqli($hostName, $dbUserName, $dbUserPass, $dbName, $port);
if (!$mysqli->connect_errno) {
$mysqli->close();
}
@@ -95,7 +95,8 @@ class SystemHelper extends \Espo\Core\Utils\System
case 'pdo_mysql':
try {
- $dbh = new PDO("mysql:host={$hostName};dbname={$dbName}", $dbUserName, $dbUserPass);
+ $dsn = "mysql:host={$hostName};" . ((!empty($port)) ? "port={$port};" : '') . "dbname={$dbName}";
+ $dbh = new PDO($dsn, $dbUserName, $dbUserPass);
$dbh = null;
} catch (PDOException $e) {
@@ -129,48 +130,9 @@ class SystemHelper extends \Espo\Core\Utils\System
return $this->modRewriteUrl;
}
- public function getChmodCommand($path, $permissions = array('755'), $isSudo = false, $isFile = null, $isCd = true)
- {
- //$path = $this->getFullPath($path);
-
- $path = empty($path) ? '*' : $path;
- if (is_array($path)) {
- $path = implode(' ', $path);
- }
-
- $sudoStr = $isSudo ? 'sudo ' : '';
-
- $cd = $isCd ? $this->getCd(true) : '';
-
- if (is_string($permissions)) {
- $permissions = (array) $permissions;
- }
-
- if (!isset($isFile) && count($permissions) == 1) {
- return $cd.$sudoStr.'chmod -R '.$permissions[0].' '.$path;
- }
-
- $bufPerm = (count($permissions) == 1) ? array_fill(0, 2, $permissions[0]) : $permissions;
-
- $commands = array();
-
- if ($isCd) {
- $commands[] = $this->getCd();
- }
-
- $commands[] = $sudoStr.'chmod '.$bufPerm[0].' $(find '.$path.' -type f)';
- $commands[] = $sudoStr.'chmod '.$bufPerm[1].' $(find '.$path.' -type d)';
-
- if (count($permissions) >= 2) {
- return implode(' ' . $this->combineOperator . ' ', $commands);
- }
-
- return $isFile ? $commands[0] : $commands[1];
- }
-
public function getChownCommand($path, $isSudo = false, $isCd = true)
{
- $path = empty($path) ? '*' : $path;
+ $path = empty($path) ? '.' : $path;
if (is_array($path)) {
$path = implode(' ', $path);
}
@@ -193,6 +155,46 @@ class SystemHelper extends \Espo\Core\Utils\System
return $cd.$sudoStr.'chown -R '.$owner.':'.$group.' '.$path;
}
+
+ public function getChmodCommand($path, $permissions = array('755'), $isSudo = false, $isFile = null, $isCd = true)
+ {
+ //$path = $this->getFullPath($path);
+
+ $path = empty($path) ? '.' : $path;
+ if (is_array($path)) {
+ $path = implode(' ', $path);
+ }
+
+ $sudoStr = $isSudo ? 'sudo ' : '';
+
+ $cd = $isCd ? $this->getCd(true) : '';
+
+ if (is_string($permissions)) {
+ $permissions = (array) $permissions;
+ }
+
+ if (!isset($isFile) && count($permissions) == 1) {
+ return $cd.'find '.$path.' -type d -exec ' . $sudoStr . 'chmod '.$permissions[0].' {} +';
+ }
+
+ $bufPerm = (count($permissions) == 1) ? array_fill(0, 2, $permissions[0]) : $permissions;
+
+ $commands = array();
+
+ if ($isCd) {
+ $commands[] = $this->getCd();
+ }
+
+ $commands[] = 'find '.$path.' -type f -exec ' .$sudoStr.'chmod '.$bufPerm[0].' {} +';//.'chmod '.$bufPerm[0].' $(find '.$path.' -type f)';
+ $commands[] = 'find '.$path.' -type d -exec ' .$sudoStr. 'chmod '.$bufPerm[1].' {} +';//.'chmod '.$bufPerm[1].' $(find '.$path.' -type d)';
+
+ if (count($permissions) >= 2) {
+ return implode(' ' . $this->combineOperator . ' ', $commands);
+ }
+
+ return $isFile ? $commands[0] : $commands[1];
+ }
+
public function getFullPath($path)
{
if (is_array($path)) {
@@ -219,7 +221,7 @@ class SystemHelper extends \Espo\Core\Utils\System
* @param bool $isFile
* @return string
*/
- public function getPermissionCommands($path, $permissions = array('644', '755'), $isSudo = false, $isFile = null)
+ public function getPermissionCommands($path, $permissions = array('644', '755'), $isSudo = false, $isFile = null, $changeOwner = true)
{
if (is_string($path)) {
$path = array_fill(0, 2, $path);
@@ -229,11 +231,12 @@ class SystemHelper extends \Espo\Core\Utils\System
$commands = array();
$commands[] = $this->getChmodCommand($chmodPath, $permissions, $isSudo, $isFile);
- $chown = $this->getChownCommand($chownPath, $isSudo, false);
- if (isset($chown)) {
- $commands[] = $chown;
+ if ($changeOwner) {
+ $chown = $this->getChownCommand($chownPath, $isSudo, false);
+ if (isset($chown)) {
+ $commands[] = $chown;
+ }
}
-
return implode(' ' . $this->combineOperator . ' ', $commands).';';
}
diff --git a/install/core/actions/applySett.php b/install/core/actions/applySett.php
index 1c4ab0dd48..e016401f6c 100644
--- a/install/core/actions/applySett.php
+++ b/install/core/actions/applySett.php
@@ -26,12 +26,16 @@ $result = array('success' => true, 'errorMsg' => '');
// save settings
$data = array(
'driver' => 'pdo_mysql',
- 'host' => $_SESSION['install']['host-name'],
- 'port' => $_SESSION['install']['port'],
'dbname' => $_SESSION['install']['db-name'],
'user' => $_SESSION['install']['db-user-name'],
'password' => $_SESSION['install']['db-user-password'],
);
+$host = $_SESSION['install']['host-name'];
+if (strpos($host,':') === false) {
+ $host .= ":";
+}
+list($data['host'], $data['port']) = explode(':', $host);
+
$lang = (!empty($_SESSION['install']['user-lang']))? $_SESSION['install']['user-lang'] : 'en_US';
if (!$installer->saveData($data, $lang)) {
$result['success'] = false;
@@ -39,4 +43,4 @@ if (!$installer->saveData($data, $lang)) {
}
ob_clean();
-echo json_encode($result);
\ No newline at end of file
+echo json_encode($result);
diff --git a/install/core/actions/checkPermission.php b/install/core/actions/checkPermission.php
index 2e03b5a578..a4091b6e43 100644
--- a/install/core/actions/checkPermission.php
+++ b/install/core/actions/checkPermission.php
@@ -31,11 +31,17 @@ if (!$installer->checkPermission()) {
foreach($error as $folder => $permission) {
$group[implode('-', $permission)][] = $folder;
}
+ ksort($group);
$instruction = '';
$instructionSU = '';
+ $changeOwner = true;
foreach($group as $permission => $folders) {
- $instruction .= $systemHelper->getPermissionCommands(array($folders, ''), explode('-', $permission)) . "
";
- $instructionSU .= " " . $systemHelper->getPermissionCommands(array($folders, ''), explode('-', $permission), true) . "
";
+ if ($permission == '0644-0755') $folders = '';
+ $instruction .= $systemHelper->getPermissionCommands(array($folders, ''), explode('-', $permission), false, null, $changeOwner) . "
";
+ $instructionSU .= " " . $systemHelper->getPermissionCommands(array($folders, ''), explode('-', $permission), true, null, $changeOwner) . "
";
+ if ($changeOwner) {
+ $changeOwner = false;
+ }
}
$result['errorMsg'] = $langs['messages']['Permission denied to'] . ':
/'.implode('
/', $urls).'';
$result['errorFixInstruction'] = str_replace( '"{C}"' , $instruction, $langs['messages']['permissionInstruction']) . "