Added option to customize database hostname and port

This commit is contained in:
Alejandro Celaya 2017-01-21 13:45:28 +01:00
parent 29fd313337
commit 869865f22a
2 changed files with 13 additions and 0 deletions

View File

@ -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'] = [

View File

@ -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',
]