Commit 57838ec1 authored by Nicolas Widart's avatar Nicolas Widart

Writing the database informations

parent f7367785
<?php namespace Modules\Core\Console; <?php namespace Modules\Core\Console;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
use Modules\User\Repositories\RoleRepository; use Modules\User\Repositories\RoleRepository;
use Modules\User\Repositories\UserRepository; use Modules\User\Repositories\UserRepository;
...@@ -30,19 +31,25 @@ class InstallCommand extends Command ...@@ -30,19 +31,25 @@ class InstallCommand extends Command
* @var RoleRepository * @var RoleRepository
*/ */
private $role; private $role;
/**
* @var Filesystem
*/
private $finder;
/** /**
* Create a new command instance. * Create a new command instance.
* *
* @param UserRepository $user * @param UserRepository $user
* @param RoleRepository $role * @param RoleRepository $role
* @param Filesystem $finder
* @return \Modules\Core\Console\InstallCommand * @return \Modules\Core\Console\InstallCommand
*/ */
public function __construct($user, $role) public function __construct($user, $role, Filesystem $finder)
{ {
parent::__construct(); parent::__construct();
$this->user = $user; $this->user = $user;
$this->role = $role; $this->role = $role;
$this->finder = $finder;
} }
/** /**
...@@ -54,6 +61,8 @@ class InstallCommand extends Command ...@@ -54,6 +61,8 @@ class InstallCommand extends Command
{ {
$this->info('Starting the installation process...'); $this->info('Starting the installation process...');
$this->configureDatabase();
$this->runMigrations(); $this->runMigrations();
$this->runSeeds(); $this->runSeeds();
...@@ -129,4 +138,47 @@ class InstallCommand extends Command ...@@ -129,4 +138,47 @@ class InstallCommand extends Command
{ {
$this->call('module:publish', ['module' => 'Core']); $this->call('module:publish', ['module' => 'Core']);
} }
/**
* Configuring the database information
*/
private function configureDatabase()
{
// Ask for credentials
$databaseName = $this->ask('Enter your database name');
$databaseUsername = $this->ask('Enter your database username');
$databasePassword = $this->secret('Enter your database password');
$this->configureEnvironmentFile($databaseName, $databaseUsername, $databasePassword);
}
/**
* Writing the environment file
* @param $databaseName
* @param $databaseUsername
* @param $databasePassword
*/
private function configureEnvironmentFile($databaseName, $databaseUsername, $databasePassword)
{
$environmentFile = $this->finder->get('.env.example');
$search = [
"DB_USERNAME=homestead",
"DB_PASSWORD=homestead"
];
$replace = [
"DB_USERNAME=$databaseUsername",
"DB_PASSWORD=$databasePassword" . PHP_EOL
];
$newEnvironmentFile = str_replace($search, $replace, $environmentFile);
$newEnvironmentFile .= "DB_NAME=$databaseName";
// Write the new environment file
$this->finder->put('.env', $newEnvironmentFile);
// Delete the old environment file
$this->finder->delete('env.example');
$this->info('Environment file written');
}
} }
...@@ -106,7 +106,8 @@ class CoreServiceProvider extends ServiceProvider ...@@ -106,7 +106,8 @@ class CoreServiceProvider extends ServiceProvider
$this->app->bindShared('command.platform.install', function($app) { $this->app->bindShared('command.platform.install', function($app) {
return new InstallCommand( return new InstallCommand(
$app['Modules\User\Repositories\UserRepository'], $app['Modules\User\Repositories\UserRepository'],
$app['Modules\User\Repositories\RoleRepository'] $app['Modules\User\Repositories\RoleRepository'],
$app['files']
); );
}); });
......
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