Skip to content

Commit d367318

Browse files
author
Thomas Pulzer
committed
Added occ install option for database-port.
Extended the database setup to store the database port. Changed the PostgreSQL connection error message for clarification.
1 parent cf7afab commit d367318

5 files changed

Lines changed: 26 additions & 7 deletions

File tree

core/Command/Maintenance/Install.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ protected function configure() {
5050
->addOption('database', null, InputOption::VALUE_REQUIRED, 'Supported database type', 'sqlite')
5151
->addOption('database-name', null, InputOption::VALUE_REQUIRED, 'Name of the database')
5252
->addOption('database-host', null, InputOption::VALUE_REQUIRED, 'Hostname of the database', 'localhost')
53+
->addOption('database-port', null, InputOption::VALUE_OPTIONAL, 'Port the database is listening on')
5354
->addOption('database-user', null, InputOption::VALUE_REQUIRED, 'User name to connect to the database')
5455
->addOption('database-pass', null, InputOption::VALUE_OPTIONAL, 'Password of the database user', null)
5556
->addOption('database-table-prefix', null, InputOption::VALUE_OPTIONAL, 'Prefix for all tables (default: oc_)', null)
@@ -106,6 +107,7 @@ protected function validateInput(InputInterface $input, OutputInterface $output,
106107
$dbUser = $input->getOption('database-user');
107108
$dbPass = $input->getOption('database-pass');
108109
$dbName = $input->getOption('database-name');
110+
$dbPort = $input->getOption('database-port');
109111
if ($db === 'oci') {
110112
// an empty hostname needs to be read from the raw parameters
111113
$dbHost = $input->getParameterOption('--database-host', '');
@@ -158,6 +160,7 @@ protected function validateInput(InputInterface $input, OutputInterface $output,
158160
'dbpass' => $dbPass,
159161
'dbname' => $dbName,
160162
'dbhost' => $dbHost,
163+
'dbport' => $dbPort,
161164
'dbtableprefix' => $dbTablePrefix,
162165
'adminlogin' => $adminLogin,
163166
'adminpass' => $adminPassword,

lib/private/Setup/AbstractDatabase.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ abstract class AbstractDatabase {
4242
/** @var string */
4343
protected $dbHost;
4444
/** @var string */
45+
protected $dbPort;
46+
/** @var string */
4547
protected $tablePrefix;
4648
/** @var IConfig */
4749
protected $config;
@@ -78,18 +80,21 @@ public function initialize($config) {
7880
$dbPass = $config['dbpass'];
7981
$dbName = $config['dbname'];
8082
$dbHost = !empty($config['dbhost']) ? $config['dbhost'] : 'localhost';
83+
$dbPort = !empty($config['dbport']) ? $config['dbport'] : '';
8184
$dbTablePrefix = isset($config['dbtableprefix']) ? $config['dbtableprefix'] : 'oc_';
8285

8386
$this->config->setSystemValues([
8487
'dbname' => $dbName,
8588
'dbhost' => $dbHost,
89+
'dbport' => $dbPort,
8690
'dbtableprefix' => $dbTablePrefix,
8791
]);
8892

8993
$this->dbUser = $dbUser;
9094
$this->dbPassword = $dbPass;
9195
$this->dbName = $dbName;
9296
$this->dbHost = $dbHost;
97+
$this->dbPort = $dbPort;
9398
$this->tablePrefix = $dbTablePrefix;
9499
}
95100

lib/private/Setup/MySQL.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,14 @@ private function connect() {
100100
'tablePrefix' => $this->tablePrefix,
101101
);
102102

103-
// adding port support
104-
if (strpos($this->dbHost, ':')) {
103+
// adding port support through installer
104+
if(!empty($this->dbPort)) {
105+
if (ctype_digit($this->dbPort)) {
106+
$connectionParams['port'] = $this->dbPort;
107+
} else {
108+
$connectionParams['unix_socket'] = $this->dbPort;
109+
}
110+
} else if (strpos($this->dbHost, ':')) {
105111
// Host variable may carry a port or socket.
106112
list($host, $portOrSocket) = explode(':', $this->dbHost, 2);
107113
if (ctype_digit($portOrSocket)) {

lib/private/Setup/OCI.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,14 @@ public function validate($config) {
6363

6464
public function setupDatabase($username) {
6565
$e_host = addslashes($this->dbHost);
66+
// adding slashes for security reasons
67+
$e_port = addslashes($this->dbPort);
6668
$e_dbname = addslashes($this->dbName);
6769
//check if the database user has admin right
6870
if ($e_host == '') {
6971
$easy_connect_string = $e_dbname; // use dbname as easy connect name
7072
} else {
71-
$easy_connect_string = '//'.$e_host.'/'.$e_dbname;
73+
$easy_connect_string = '//'.$e_host.(!empty($e_port) ? ":{$e_port}" : "").'/'.$e_dbname;
7274
}
7375
$this->logger->debug('connect string: ' . $easy_connect_string, ['app' => 'setup.oci']);
7476
$connection = @oci_connect($this->dbUser, $this->dbPassword, $easy_connect_string);

lib/private/Setup/PostgreSQL.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ public function setupDatabase($username) {
3434
$e_user = addslashes($this->dbUser);
3535
$e_password = addslashes($this->dbPassword);
3636

37-
// Fix database with port connection
38-
if(strpos($e_host, ':')) {
37+
// adding port support through installer
38+
if(!empty($this->dbPort)) {
39+
// adding slashes for security reasons
40+
$port = addslashes($this->dbPort);
41+
} else if(strpos($e_host, ':')) {
3942
list($e_host, $port)=explode(':', $e_host, 2);
4043
} else {
4144
$port=false;
@@ -51,8 +54,8 @@ public function setupDatabase($username) {
5154
$connection = @pg_connect($connection_string);
5255

5356
if(!$connection)
54-
throw new \OC\DatabaseSetupException($this->trans->t('PostgreSQL username and/or password not valid'),
55-
$this->trans->t('You need to enter either an existing account or the administrator.'));
57+
throw new \OC\DatabaseSetupException($this->trans->t('PostgreSQL connection failed'),
58+
$this->trans->t('Please check your connection details.'));
5659
}
5760
$e_user = pg_escape_string($this->dbUser);
5861
//check for roles creation rights in postgresql

0 commit comments

Comments
 (0)