diff --git a/CHANGELOG.md b/CHANGELOG.md index b0b91ec7..6bd27f91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - API: Allow a `fields` object to set custom PIREP fields, also returns the current values - Setting: Restrict to aircraft that are at a flight's departure airport [#171](https://github.com/nabeelio/phpvms/issues/171) - Setting: Implementation of filtering flights that are only at the user's current airport [#174](https://github.com/nabeelio/phpvms/issues/174) +- Console: Added `php artisan phpvms:dev-install` command which creates the config files and creates the database/inserts sample data in one command [#176](https://github.com/nabeelio/phpvms/issues/176) #### Fixes diff --git a/app/Console/Commands/DevInstall.php b/app/Console/Commands/DevInstall.php new file mode 100644 index 00000000..47c85249 --- /dev/null +++ b/app/Console/Commands/DevInstall.php @@ -0,0 +1,94 @@ +rewriteConfigs(); + + # Reload the configuration + \App::boot(); + + $this->info('Recreating database'); + \Artisan::call('database:create', [ + '--reset' => true, + ]); + + $this->info(\Artisan::output()); + + # + # + + $this->info('Running migrations'); + \Artisan::call('migrate:fresh', [ + '--seed' => true, + ]); + + $this->info(\Artisan::output()); + + # + # + + $this->info('Importing sample data'); + \Artisan::call('phpvms:import', [ + 'files' => ['app/Database/seeds/sample.yml'], + ]); + + $this->info(\Artisan::output()); + + $this->info('Done!'); + } + + /** + * Rewrite the configuration files + * @throws \Symfony\Component\HttpFoundation\File\Exception\FileException + */ + protected function rewriteConfigs() + { + $cfgSvc = app(ConfigService::class); + + $this->info('Removing the old config files'); + + # Remove the old files + $config_file = base_path('config.php'); + if(file_exists($config_file)) { + unlink($config_file); + } + + $env_file = base_path('env.php'); + if(file_exists($env_file)) { + unlink($env_file); + } + + $this->info('Removing the sqlite db'); + $db_file = storage_path('db.sqlite'); + if(file_exists($db_file)) { + unlink($db_file); + } + + $this->info('Regenerating the config files'); + $cfgSvc->createConfigFiles([ + 'APP_ENV' => 'dev', + 'SITE_NAME' => 'phpvms test', + 'DB_CONN' => 'sqlite', + ]); + + $this->info('Config files generated!'); + } +} diff --git a/modules/Installer/Services/ConfigService.php b/modules/Installer/Services/ConfigService.php index 1b1c7769..440953fc 100644 --- a/modules/Installer/Services/ConfigService.php +++ b/modules/Installer/Services/ConfigService.php @@ -29,7 +29,7 @@ class ConfigService 'SITE_URL' => 'http://phpvms.test', 'DB_CONN' => '', 'DB_HOST' => '', - 'DB_PORT' => '', + 'DB_PORT' => 3306, 'DB_NAME' => '', 'DB_USER' => '', 'DB_PASS' => '',