From 02b429cb3277acafdd5b13fc114b4e10c9a5df2a Mon Sep 17 00:00:00 2001 From: Taras Machyshyn Date: Tue, 24 Jun 2014 11:43:37 +0300 Subject: [PATCH] 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 @@ - -