From 3332469c35a7efc4dc0cfebe88083670638b39d7 Mon Sep 17 00:00:00 2001 From: Taras Machyshyn Date: Thu, 19 Jun 2014 12:42:57 +0300 Subject: [PATCH 1/2] chnaged Config.php . Now use ->save() to save the configuration --- application/Espo/Controllers/Settings.php | 13 +++--- application/Espo/Core/Upgrades/Base.php | 3 ++ application/Espo/Core/Utils/Config.php | 49 +++++++++++------------ install/core/Installer.php | 7 +++- tests/Espo/Core/Utils/ConfigTest.php | 12 ++++-- 5 files changed, 47 insertions(+), 37 deletions(-) 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/tests/Espo/Core/Utils/ConfigTest.php b/tests/Espo/Core/Utils/ConfigTest.php index bfce8f7909..14874c6e63 100644 --- a/tests/Espo/Core/Utils/ConfigTest.php +++ b/tests/Espo/Core/Utils/ConfigTest.php @@ -67,10 +67,12 @@ class ConfigTest extends \PHPUnit_Framework_TestCase $setKey= 'testOption'; $setValue= 'Test'; - $this->assertTrue($this->object->set($setKey, $setValue)); + $this->object->set($setKey, $setValue); + $this->assertTrue($this->object->save()); $this->assertEquals($setValue, $this->object->get($setKey)); - $this->assertTrue($this->object->set($setKey, 'Another Wrong Value')); + $this->object->set($setKey, 'Another Wrong Value'); + $this->assertTrue($this->object->save()); } public function testSetArray() @@ -80,14 +82,16 @@ class ConfigTest extends \PHPUnit_Framework_TestCase 'testOption2' => 'Test2', ); - $this->assertTrue($this->object->set($values)); + $this->object->set($values); + $this->assertTrue($this->object->save()); $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->object->set($wrongArray); + $this->assertTrue($this->object->save()); } public function testSystemConfigMerge() From 02b429cb3277acafdd5b13fc114b4e10c9a5df2a Mon Sep 17 00:00:00 2001 From: Taras Machyshyn Date: Tue, 24 Jun 2014 11:43:37 +0300 Subject: [PATCH 2/2] installer: design changes --- install/core/SystemHelper.php | 99 ++++++++++++------------ install/core/actions/applySett.php | 10 ++- install/core/actions/checkPermission.php | 10 ++- install/core/actions/settingsTest.php | 9 ++- install/core/i18n/de_DE/install.json | 3 +- install/core/i18n/en_US/install.json | 3 +- install/core/i18n/es_ES/install.json | 3 +- install/core/tpl/main.tpl | 6 +- install/core/tpl/step2.tpl | 61 ++++++--------- install/css/install.css | 7 ++ 10 files changed, 113 insertions(+), 98 deletions(-) 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']) . "
" . diff --git a/install/core/actions/settingsTest.php b/install/core/actions/settingsTest.php index 860eae85c9..c2666f49ec 100644 --- a/install/core/actions/settingsTest.php +++ b/install/core/actions/settingsTest.php @@ -34,12 +34,15 @@ if (!empty($_REQUEST['dbName']) && !empty($_REQUEST['hostName']) && !empty($_REQ $connect = false; $dbName = trim($_REQUEST['dbName']); - $hostName = trim($_REQUEST['hostName']); + if (strpos($_REQUEST['hostName'],':') === false) { + $_REQUEST['hostName'] .= ":"; + } + list($hostName, $port) = explode(':', trim($_REQUEST['hostName'])); $dbUserName = trim($_REQUEST['dbUserName']); $dbUserPass = trim($_REQUEST['dbUserPass']); $dbDriver = (!empty($_REQUEST['dbDriver']))? $_REQUEST['dbDriver'] : 'pdo_mysql'; - $res = $systemHelper->checkDbConnection($hostName, $dbUserName, $dbUserPass, $dbName, $dbDriver); + $res = $systemHelper->checkDbConnection($hostName, $port, $dbUserName, $dbUserPass, $dbName, $dbDriver); $result['success'] &= $res['success']; if (!empty($res['errors'])) { $result['errors'] = array_merge($result['errors'], $res['errors']); @@ -48,4 +51,4 @@ if (!empty($_REQUEST['dbName']) && !empty($_REQUEST['hostName']) && !empty($_REQ } ob_clean(); -echo json_encode($result); \ No newline at end of file +echo json_encode($result); diff --git a/install/core/i18n/de_DE/install.json b/install/core/i18n/de_DE/install.json index a7228c520b..0ec21740b6 100644 --- a/install/core/i18n/de_DE/install.json +++ b/install/core/i18n/de_DE/install.json @@ -24,7 +24,8 @@ "Next": "Next", "Go to EspoCRM": "Go to EspoCRM", "Re-check": "Re-check", - "Test settings": "Test Connection" + "Test settings": "Test Connection", + "Database Settings Description": "Enter your MySQL database connection information (hostname, username and password). You can specify the server port for hostname like localhost:3306." }, "fields": { "Choose your language:": "Choose your language:", diff --git a/install/core/i18n/en_US/install.json b/install/core/i18n/en_US/install.json index a7228c520b..0ec21740b6 100644 --- a/install/core/i18n/en_US/install.json +++ b/install/core/i18n/en_US/install.json @@ -24,7 +24,8 @@ "Next": "Next", "Go to EspoCRM": "Go to EspoCRM", "Re-check": "Re-check", - "Test settings": "Test Connection" + "Test settings": "Test Connection", + "Database Settings Description": "Enter your MySQL database connection information (hostname, username and password). You can specify the server port for hostname like localhost:3306." }, "fields": { "Choose your language:": "Choose your language:", diff --git a/install/core/i18n/es_ES/install.json b/install/core/i18n/es_ES/install.json index 0b85071213..303f7ea842 100644 --- a/install/core/i18n/es_ES/install.json +++ b/install/core/i18n/es_ES/install.json @@ -23,7 +23,8 @@ "Next": "Siguiente", "Go to EspoCRM": "Ir a EspoCRM(Español)", "Re-check": "Revisar otra vez", - "Test settings": "Test de conexión" + "Test settings": "Test de conexión", + "Database Settings Description": "Enter your MySQL database connection information (hostname, username and password). You can specify the server port for hostname like localhost:3306." }, "fields": { "Choose your language:": "Seleccione un lenguaje:", diff --git a/install/core/tpl/main.tpl b/install/core/tpl/main.tpl index d455ffe7f6..0a21aace23 100644 --- a/install/core/tpl/main.tpl +++ b/install/core/tpl/main.tpl @@ -14,8 +14,6 @@ - -