From 5cce1b3040052cb25e5cd271281d07cfe5d93056 Mon Sep 17 00:00:00 2001 From: Nabeel S Date: Wed, 7 Aug 2019 12:32:49 -0400 Subject: [PATCH] Multiple ticket crash fixes (#347) * Fix for initial seed data not being run during install closes #346 * StyleCI keepin' me honest * Tooltips for ranks --- app/Console/Commands/DevCommands.php | 35 ++++++++++++- app/Database/seeds/prod/prod.yml | 16 ------ .../Http/Controllers/InstallerController.php | 52 ++++++++++--------- resources/stubs/installer/config.stub | 7 ++- resources/views/admin/ranks/fields.blade.php | 21 ++++++-- 5 files changed, 84 insertions(+), 47 deletions(-) delete mode 100644 app/Database/seeds/prod/prod.yml diff --git a/app/Console/Commands/DevCommands.php b/app/Console/Commands/DevCommands.php index adeb437f..bdb72905 100644 --- a/app/Console/Commands/DevCommands.php +++ b/app/Console/Commands/DevCommands.php @@ -9,7 +9,8 @@ use App\Models\Pirep; use App\Models\User; use App\Services\AwardService; use App\Services\DatabaseService; -use DB; +use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Schema; use PDO; use Symfony\Component\Yaml\Yaml; @@ -46,12 +47,13 @@ class DevCommands extends Command } $commands = [ - 'list-awards' => 'listAwardClasses', 'clear-acars' => 'clearAcars', 'clear-users' => 'clearUsers', 'compile-assets' => 'compileAssets', 'db-attrs' => 'dbAttrs', + 'list-awards' => 'listAwardClasses', 'manual-insert' => 'manualInsert', + 'reset-install' => 'resetInstall', 'xml-to-yaml' => 'xmlToYaml', ]; @@ -212,4 +214,33 @@ class DevCommands extends Command } } } + + /** + * Delete all of the tables, etc from the database, for a clean install + */ + protected function resetInstall(): void + { + $confirm = $this->ask('This will erase your entire install and database, are you sure? y/n '); + if (strtolower($confirm) !== 'y') { + exit(0); + } + + if (config('database.default') === 'mysql') { + DB::statement('SET foreign_key_checks=0'); + } + + $this->info('Dropping all tables'); + $tables = DB::connection()->getDoctrineSchemaManager()->listTableNames(); + foreach ($tables as $table) { + Schema::dropIfExists($table); + } + + $this->info('Deleting config file'); + unlink('config.php'); + + $this->info('Deleting env file'); + unlink('env.php'); + + $this->info('Done!'); + } } diff --git a/app/Database/seeds/prod/prod.yml b/app/Database/seeds/prod/prod.yml deleted file mode 100644 index 0c3cca14..00000000 --- a/app/Database/seeds/prod/prod.yml +++ /dev/null @@ -1,16 +0,0 @@ -# -# Initial minimal data required. You probably don't -# want to modify or erase any of this here -# - -airports: - - id: KAUS - iata: AUS - icao: KAUS - name: Austin-Bergstrom - location: Austin, Texas, USA - country: United States - timezone: America/Chicago - lat: 30.1945278 - lon: -97.6698889 - hub: 1 diff --git a/modules/Installer/Http/Controllers/InstallerController.php b/modules/Installer/Http/Controllers/InstallerController.php index 37b79684..bcc49cb3 100644 --- a/modules/Installer/Http/Controllers/InstallerController.php +++ b/modules/Installer/Http/Controllers/InstallerController.php @@ -8,13 +8,14 @@ use App\Models\User; use App\Repositories\AirlineRepository; use App\Services\AnalyticsService; use App\Services\Installer\MigrationService; +use App\Services\Installer\SeederService; use App\Services\UserService; use App\Support\Countries; use Illuminate\Database\QueryException; use Illuminate\Http\Request; use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Validator; -use Log; use Modules\Installer\Services\ConfigService; use Modules\Installer\Services\DatabaseService; use Modules\Installer\Services\RequirementsService; @@ -28,21 +29,23 @@ class InstallerController extends Controller { private $airlineRepo, $analyticsSvc, - $dbService, - $envService, + $dbSvc, + $envSvc, $migrationSvc, - $reqService, + $reqSvc, + $seederSvc, $userService; /** * InstallerController constructor. - * @param AirlineRepository $airlineRepo - * @param AnalyticsService $analyticsSvc - * @param DatabaseService $dbService - * @param ConfigService $envService - * @param MigrationService $migrationSvc - * @param RequirementsService $reqService - * @param UserService $userService + * @param AirlineRepository $airlineRepo + * @param AnalyticsService $analyticsSvc + * @param DatabaseService $dbService + * @param ConfigService $envService + * @param MigrationService $migrationSvc + * @param RequirementsService $reqSvc + * @param SeederService $seederSvc + * @param UserService $userService */ public function __construct( AirlineRepository $airlineRepo, @@ -50,15 +53,17 @@ class InstallerController extends Controller DatabaseService $dbService, ConfigService $envService, MigrationService $migrationSvc, - RequirementsService $reqService, + RequirementsService $reqSvc, + SeederService $seederSvc, UserService $userService ) { $this->airlineRepo = $airlineRepo; $this->analyticsSvc = $analyticsSvc; - $this->dbService = $dbService; - $this->envService = $envService; + $this->dbSvc = $dbService; + $this->envSvc = $envService; $this->migrationSvc = $migrationSvc; - $this->reqService = $reqService; + $this->reqSvc = $reqSvc; + $this->seederSvc = $seederSvc; $this->userService = $userService; } /** @@ -75,7 +80,7 @@ class InstallerController extends Controller protected function testDb(Request $request) { - $this->dbService->checkDbConnection( + $this->dbSvc->checkDbConnection( $request->post('db_conn'), $request->post('db_host'), $request->post('db_port'), @@ -131,9 +136,9 @@ class InstallerController extends Controller */ public function step1(Request $request) { - $php_version = $this->reqService->checkPHPVersion(); - $extensions = $this->reqService->checkExtensions(); - $directories = $this->reqService->checkPermissions(); + $php_version = $this->reqSvc->checkPHPVersion(); + $extensions = $this->reqSvc->checkExtensions(); + $directories = $this->reqSvc->checkPermissions(); # Only pass if all the items in the ext and dirs are passed $statuses = [ @@ -210,7 +215,7 @@ class InstallerController extends Controller * setup the database and stuff */ try { - $this->envService->createConfigFiles($attrs); + $this->envSvc->createConfigFiles($attrs); } catch(FileException $e) { Log::error('Config files failed to write'); Log::error($e->getMessage()); @@ -234,12 +239,13 @@ class InstallerController extends Controller $console_out = ''; try { - $console_out .= $this->dbService->setupDB(); + $console_out .= $this->dbSvc->setupDB(); $console_out .= $this->migrationSvc->runAllMigrations(); + $this->seederSvc->syncAllSeeds(); } catch(QueryException $e) { Log::error('Error on db setup: ' . $e->getMessage()); - $this->envService->removeConfigFiles(); + $this->envSvc->removeConfigFiles(); flash()->error($e->getMessage()); return redirect(route('installer.step2'))->withInput(); } @@ -309,8 +315,6 @@ class InstallerController extends Controller 'email' => $request->get('email'), 'api_key' => Utils::generateApiKey(), 'airline_id' => $airline->id, - 'home_airport_id' => 'KAUS', - 'curr_airport_id' => 'KAUS', 'password' => Hash::make($request->get('password')) ]; diff --git a/resources/stubs/installer/config.stub b/resources/stubs/installer/config.stub index 2b8fbd06..1435152a 100644 --- a/resources/stubs/installer/config.stub +++ b/resources/stubs/installer/config.stub @@ -12,8 +12,11 @@ return [ 'name' => '$SITE_NAME$', 'url' => '$SITE_URL$', - # Don't forget to change these when live + // When live, 'env' should be 'prod' 'env' => 'prod', + + // debug as true shows the Laravel debug bar, which is helpful for + // debugging templates and other internals 'debug' => false, ], @@ -71,7 +74,7 @@ return [ 'default' => env('DB_CONNECTION', '$DB_CONN$'), 'connections' => [ 'mysql' => [ - 'host' => '$DB_HOST$', + 'host' => env('DB_HOST', '$DB_HOST$'), 'port' => $DB_PORT$, 'database' => '$DB_NAME$', 'username' => '$DB_USER$', diff --git a/resources/views/admin/ranks/fields.blade.php b/resources/views/admin/ranks/fields.blade.php index 9f9c6fc2..1efd47df 100644 --- a/resources/views/admin/ranks/fields.blade.php +++ b/resources/views/admin/ranks/fields.blade.php @@ -50,35 +50,50 @@
-
+
+
+ @component('admin.components.info') + PIREPS submitted through ACARS are automatically accepted + @endcomponent +
-
+
+
+ @component('admin.components.info') + PIREPS submitted manually are automatically accepted + @endcomponent +
-
+
+
+ @component('admin.components.info') + When a pilot reaches these hours, they'll be upgraded to this rank + @endcomponent +