Commit 2198b382 authored by Marcus Reinhardt's avatar Marcus Reinhardt Committed by Nicolas Widart

Allow other database drivers (#323)

* Allow other database drivers

With this changes, it's possible to define another database driver.
It's now also possible to change the port.

Moved from https://github.com/AsgardCms/Core/pull/103

* Update ConfigureDatabase.php

removed spaces

* Update EnvFileWriter.php
parent 59dc09da
...@@ -47,15 +47,14 @@ class ConfigureDatabase implements SetupScript ...@@ -47,15 +47,14 @@ class ConfigureDatabase implements SetupScript
$connected = false; $connected = false;
while (! $connected) { while (! $connected) {
$driver = $this->askDatabaseDriver();
$host = $this->askDatabaseHost(); $host = $this->askDatabaseHost();
$port = $this->askDatabasePort($driver);
$name = $this->askDatabaseName(); $name = $this->askDatabaseName();
$user = $this->askDatabaseUsername(); $user = $this->askDatabaseUsername();
$password = $this->askDatabasePassword(); $password = $this->askDatabasePassword();
$this->setLaravelConfiguration($name, $user, $password, $host); $this->setLaravelConfiguration($driver, $host, $port, $name, $user, $password);
if ($this->databaseConnectionIsValid()) { if ($this->databaseConnectionIsValid()) {
$connected = true; $connected = true;
...@@ -64,21 +63,38 @@ class ConfigureDatabase implements SetupScript ...@@ -64,21 +63,38 @@ class ConfigureDatabase implements SetupScript
} }
} }
$this->env->write($name, $user, $password, $host); $this->env->write($driver, $host, $port,$name, $user, $password);
$command->info('Database successfully configured'); $command->info('Database successfully configured');
} }
/**
* @return string
*/
protected function askDatabaseDriver()
{
$driver = $this->command->ask('Enter your database driver (e.g. mysql, pgsql)', 'mysql');
return $driver;
}
/** /**
* @return string * @return string
*/ */
protected function askDatabaseHost() protected function askDatabaseHost()
{ {
$host = $this->command->ask('Enter your database host', 'localhost'); $host = $this->command->ask('Enter your database host', 'localhost');
return $host; return $host;
} }
/**
* @return string
*/
protected function askDatabasePort($driver)
{
$port = $this->command->ask('Enter your database port', $this->config['database.connections.'.$driver.'.port']);
return $port;
}
/** /**
* @return string * @return string
*/ */
...@@ -122,16 +138,20 @@ class ConfigureDatabase implements SetupScript ...@@ -122,16 +138,20 @@ class ConfigureDatabase implements SetupScript
} }
/** /**
* @param $driver
* @param $name * @param $name
* @param $port
* @param $user * @param $user
* @param $password * @param $password
*/ */
protected function setLaravelConfiguration($name, $user, $password, $host) protected function setLaravelConfiguration($driver, $host, $port, $name, $user, $password)
{ {
$this->config['database.connections.mysql.host'] = $host; $this->config['database.default'] = $driver;
$this->config['database.connections.mysql.database'] = $name; $this->config['database.connections.'.$driver.'.host'] = $host;
$this->config['database.connections.mysql.username'] = $user; $this->config['database.connections.'.$driver.'.port'] = $port;
$this->config['database.connections.mysql.password'] = $password; $this->config['database.connections.'.$driver.'.database'] = $name;
$this->config['database.connections.'.$driver.'.username'] = $user;
$this->config['database.connections.'.$driver.'.password'] = $password;
} }
/** /**
......
...@@ -15,6 +15,8 @@ class EnvFileWriter ...@@ -15,6 +15,8 @@ class EnvFileWriter
* @var array * @var array
*/ */
protected $search = [ protected $search = [
"DB_CONNECTION=mysql",
"DB_PORT=3306",
"DB_HOST=localhost", "DB_HOST=localhost",
"DB_DATABASE=homestead", "DB_DATABASE=homestead",
"DB_USERNAME=homestead", "DB_USERNAME=homestead",
...@@ -40,17 +42,22 @@ class EnvFileWriter ...@@ -40,17 +42,22 @@ class EnvFileWriter
} }
/** /**
* @param $driver
* @param $host
* @param $port
* @param $name * @param $name
* @param $username * @param $username
* @param $password * @param $password
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/ */
public function write($name, $username, $password, $host) public function write($driver, $host, $port, $name, $username, $password)
{ {
$environmentFile = $this->finder->get($this->template); $environmentFile = $this->finder->get($this->template);
$replace = [ $replace = [
"DB_CONNECTION=$driver",
"DB_HOST=$host", "DB_HOST=$host",
"DB_PORT=$port"
"DB_DATABASE=$name", "DB_DATABASE=$name",
"DB_USERNAME=$username", "DB_USERNAME=$username",
"DB_PASSWORD=$password", "DB_PASSWORD=$password",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment