diff --git a/Modules/Core/Console/InstallCommand.php b/Modules/Core/Console/InstallCommand.php index 240afdc81257e68a7d7fd07646fcde5f1488324c..03f2beefda24c09eb681838ed65db55f11c1f327 100644 --- a/Modules/Core/Console/InstallCommand.php +++ b/Modules/Core/Console/InstallCommand.php @@ -1,6 +1,7 @@ <?php namespace Modules\Core\Console; use Illuminate\Console\Command; +use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Facades\Hash; use Modules\User\Repositories\RoleRepository; use Modules\User\Repositories\UserRepository; @@ -30,19 +31,25 @@ class InstallCommand extends Command * @var RoleRepository */ private $role; + /** + * @var Filesystem + */ + private $finder; /** * Create a new command instance. * * @param UserRepository $user * @param RoleRepository $role + * @param Filesystem $finder * @return \Modules\Core\Console\InstallCommand */ - public function __construct($user, $role) + public function __construct($user, $role, Filesystem $finder) { parent::__construct(); $this->user = $user; $this->role = $role; + $this->finder = $finder; } /** @@ -54,6 +61,8 @@ class InstallCommand extends Command { $this->info('Starting the installation process...'); + $this->configureDatabase(); + $this->runMigrations(); $this->runSeeds(); @@ -129,4 +138,47 @@ class InstallCommand extends Command { $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'); + } } diff --git a/Modules/Core/Providers/CoreServiceProvider.php b/Modules/Core/Providers/CoreServiceProvider.php index 0ba9858d48c7b93c84238ffd481a5ea5315446f8..59cdfb83a6fb5b706cb68efc6beac18c977377d1 100644 --- a/Modules/Core/Providers/CoreServiceProvider.php +++ b/Modules/Core/Providers/CoreServiceProvider.php @@ -106,7 +106,8 @@ class CoreServiceProvider extends ServiceProvider $this->app->bindShared('command.platform.install', function($app) { return new InstallCommand( $app['Modules\User\Repositories\UserRepository'], - $app['Modules\User\Repositories\RoleRepository'] + $app['Modules\User\Repositories\RoleRepository'], + $app['files'] ); });