From 869865f22a5b88380fb33b91862e9a86df723c20 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 21 Jan 2017 13:45:28 +0100 Subject: [PATCH] Added option to customize database hostname and port --- module/CLI/src/Command/Install/InstallCommand.php | 9 +++++++++ module/CLI/test/Command/Install/InstallCommandTest.php | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/module/CLI/src/Command/Install/InstallCommand.php b/module/CLI/src/Command/Install/InstallCommand.php index cdee0cb0..b331511a 100644 --- a/module/CLI/src/Command/Install/InstallCommand.php +++ b/module/CLI/src/Command/Install/InstallCommand.php @@ -135,11 +135,18 @@ class InstallCommand extends Command $params['NAME'] = $this->ask('Database name', 'shlink'); $params['USER'] = $this->ask('Database username'); $params['PASSWORD'] = $this->ask('Database password'); + $params['HOST'] = $this->ask('Database host', 'localhost'); + $params['PORT'] = $this->ask('Database port', $this->getDefaultDbPort($params['DRIVER'])); } return $params; } + protected function getDefaultDbPort($driver) + { + return $driver === 'pdo_mysql' ? '3306' : '5432'; + } + protected function askUrlShortener() { $this->printTitle('URL SHORTENER'); @@ -272,6 +279,8 @@ class InstallCommand extends Command $config['entity_manager']['connection']['user'] = $params['DATABASE']['USER']; $config['entity_manager']['connection']['password'] = $params['DATABASE']['PASSWORD']; $config['entity_manager']['connection']['dbname'] = $params['DATABASE']['NAME']; + $config['entity_manager']['connection']['host'] = $params['DATABASE']['HOST']; + $config['entity_manager']['connection']['port'] = $params['DATABASE']['PORT']; if ($params['DATABASE']['DRIVER'] === 'pdo_mysql') { $config['entity_manager']['connection']['driverOptions'] = [ diff --git a/module/CLI/test/Command/Install/InstallCommandTest.php b/module/CLI/test/Command/Install/InstallCommandTest.php index ebe1874f..59374241 100644 --- a/module/CLI/test/Command/Install/InstallCommandTest.php +++ b/module/CLI/test/Command/Install/InstallCommandTest.php @@ -53,6 +53,8 @@ class InstallCommandTest extends TestCase shlink_db alejandro 1234 + + 0 doma.in abc123BCA @@ -81,6 +83,8 @@ CLI_INPUT 'dbname' => 'shlink_db', 'user' => 'alejandro', 'password' => '1234', + 'host' => 'localhost', + 'port' => '3306', 'driverOptions' => [ \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', ]