Skip to content

Commit

Permalink
Added new phpvms:dev-install command #176
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeelio committed Feb 9, 2018
1 parent 390f08d commit d94294e
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
94 changes: 94 additions & 0 deletions app/Console/Commands/DevInstall.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace App\Console\Commands;

use App\Console\BaseCommand;
use Modules\Installer\Services\ConfigService;

/**
* Create a fresh development install
* @package App\Console\Commands
*/
class DevInstall extends BaseCommand
{
protected $signature = 'phpvms:dev-install';
protected $description = 'Run a developer install and run the sample migration';

/**
* Run dev related commands
* @throws \Symfony\Component\HttpFoundation\File\Exception\FileException
*/
public function handle()
{
$this->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!');
}
}
2 changes: 1 addition & 1 deletion modules/Installer/Services/ConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function createConfigFiles($attrs): bool
'SITE_URL' => 'http://phpvms.test',
'DB_CONN' => '',
'DB_HOST' => '',
'DB_PORT' => '',
'DB_PORT' => 3306,
'DB_NAME' => '',
'DB_USER' => '',
'DB_PASS' => '',
Expand Down

0 comments on commit d94294e

Please sign in to comment.