diff options
author | Thomas Pulzer <t.pulzer@kniel.de> | 2016-07-06 09:58:38 +0200 |
---|---|---|
committer | Thomas Pulzer <t.pulzer@kniel.de> | 2016-07-06 09:58:38 +0200 |
commit | d367318088c2044427a574b1e42c48deade1bec3 (patch) | |
tree | a3cc8b55540ab039eb07f5d2be180c545578bedb /lib/private | |
parent | cf7afabf62d1e3f4c5856d7636e21496d7992257 (diff) | |
download | nextcloud-server-d367318088c2044427a574b1e42c48deade1bec3.tar.gz nextcloud-server-d367318088c2044427a574b1e42c48deade1bec3.zip |
Added occ install option for database-port.
Extended the database setup to store the database port.
Changed the PostgreSQL connection error message for clarification.
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Setup/AbstractDatabase.php | 5 | ||||
-rw-r--r-- | lib/private/Setup/MySQL.php | 10 | ||||
-rw-r--r-- | lib/private/Setup/OCI.php | 4 | ||||
-rw-r--r-- | lib/private/Setup/PostgreSQL.php | 11 |
4 files changed, 23 insertions, 7 deletions
diff --git a/lib/private/Setup/AbstractDatabase.php b/lib/private/Setup/AbstractDatabase.php index 331617df19d..08ed741f51c 100644 --- a/lib/private/Setup/AbstractDatabase.php +++ b/lib/private/Setup/AbstractDatabase.php @@ -42,6 +42,8 @@ abstract class AbstractDatabase { /** @var string */ protected $dbHost; /** @var string */ + protected $dbPort; + /** @var string */ protected $tablePrefix; /** @var IConfig */ protected $config; @@ -78,11 +80,13 @@ abstract class AbstractDatabase { $dbPass = $config['dbpass']; $dbName = $config['dbname']; $dbHost = !empty($config['dbhost']) ? $config['dbhost'] : 'localhost'; + $dbPort = !empty($config['dbport']) ? $config['dbport'] : ''; $dbTablePrefix = isset($config['dbtableprefix']) ? $config['dbtableprefix'] : 'oc_'; $this->config->setSystemValues([ 'dbname' => $dbName, 'dbhost' => $dbHost, + 'dbport' => $dbPort, 'dbtableprefix' => $dbTablePrefix, ]); @@ -90,6 +94,7 @@ abstract class AbstractDatabase { $this->dbPassword = $dbPass; $this->dbName = $dbName; $this->dbHost = $dbHost; + $this->dbPort = $dbPort; $this->tablePrefix = $dbTablePrefix; } diff --git a/lib/private/Setup/MySQL.php b/lib/private/Setup/MySQL.php index 1467eb734d7..1ff7b278b86 100644 --- a/lib/private/Setup/MySQL.php +++ b/lib/private/Setup/MySQL.php @@ -100,8 +100,14 @@ class MySQL extends AbstractDatabase { 'tablePrefix' => $this->tablePrefix, ); - // adding port support - if (strpos($this->dbHost, ':')) { + // adding port support through installer + if(!empty($this->dbPort)) { + if (ctype_digit($this->dbPort)) { + $connectionParams['port'] = $this->dbPort; + } else { + $connectionParams['unix_socket'] = $this->dbPort; + } + } else if (strpos($this->dbHost, ':')) { // Host variable may carry a port or socket. list($host, $portOrSocket) = explode(':', $this->dbHost, 2); if (ctype_digit($portOrSocket)) { diff --git a/lib/private/Setup/OCI.php b/lib/private/Setup/OCI.php index 1da3656f9ab..7fddf0e58e5 100644 --- a/lib/private/Setup/OCI.php +++ b/lib/private/Setup/OCI.php @@ -63,12 +63,14 @@ class OCI extends AbstractDatabase { public function setupDatabase($username) { $e_host = addslashes($this->dbHost); + // adding slashes for security reasons + $e_port = addslashes($this->dbPort); $e_dbname = addslashes($this->dbName); //check if the database user has admin right if ($e_host == '') { $easy_connect_string = $e_dbname; // use dbname as easy connect name } else { - $easy_connect_string = '//'.$e_host.'/'.$e_dbname; + $easy_connect_string = '//'.$e_host.(!empty($e_port) ? ":{$e_port}" : "").'/'.$e_dbname; } $this->logger->debug('connect string: ' . $easy_connect_string, ['app' => 'setup.oci']); $connection = @oci_connect($this->dbUser, $this->dbPassword, $easy_connect_string); diff --git a/lib/private/Setup/PostgreSQL.php b/lib/private/Setup/PostgreSQL.php index 702227ef3ff..35d8b8eac14 100644 --- a/lib/private/Setup/PostgreSQL.php +++ b/lib/private/Setup/PostgreSQL.php @@ -34,8 +34,11 @@ class PostgreSQL extends AbstractDatabase { $e_user = addslashes($this->dbUser); $e_password = addslashes($this->dbPassword); - // Fix database with port connection - if(strpos($e_host, ':')) { + // adding port support through installer + if(!empty($this->dbPort)) { + // adding slashes for security reasons + $port = addslashes($this->dbPort); + } else if(strpos($e_host, ':')) { list($e_host, $port)=explode(':', $e_host, 2); } else { $port=false; @@ -51,8 +54,8 @@ class PostgreSQL extends AbstractDatabase { $connection = @pg_connect($connection_string); if(!$connection) - throw new \OC\DatabaseSetupException($this->trans->t('PostgreSQL username and/or password not valid'), - $this->trans->t('You need to enter either an existing account or the administrator.')); + throw new \OC\DatabaseSetupException($this->trans->t('PostgreSQL connection failed'), + $this->trans->t('Please check your connection details.')); } $e_user = pg_escape_string($this->dbUser); //check for roles creation rights in postgresql |