From 380c9d13b648ffd69bad6388d83ad211a8aafe59 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Thu, 8 Aug 2019 13:42:43 -0400 Subject: [PATCH] Error handling around reset install; clear cache --- app/Console/Commands/DevCommands.php | 34 ++++++++++++++----- config/modules.php | 2 +- .../Http/Controllers/InstallerController.php | 2 +- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/app/Console/Commands/DevCommands.php b/app/Console/Commands/DevCommands.php index bdb72905..9d4d0a1e 100644 --- a/app/Console/Commands/DevCommands.php +++ b/app/Console/Commands/DevCommands.php @@ -9,6 +9,8 @@ use App\Models\Pirep; use App\Models\User; use App\Services\AwardService; use App\Services\DatabaseService; +use Illuminate\Database\QueryException; +use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; use PDO; @@ -225,21 +227,35 @@ class DevCommands extends Command exit(0); } - if (config('database.default') === 'mysql') { - DB::statement('SET foreign_key_checks=0'); - } + try { + 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('Dropping all tables'); + $tables = DB::connection()->getDoctrineSchemaManager()->listTableNames(); + foreach ($tables as $table) { + Schema::dropIfExists($table); + } + } catch (QueryException $e) { + $this->error('DB error: '.$e->getMessage()); } $this->info('Deleting config file'); - unlink('config.php'); + try { + unlink('config.php'); + } catch (\Exception $e) { } $this->info('Deleting env file'); - unlink('env.php'); + try { + unlink('env.php'); + } catch (\Exception $e) { } + + $this->info('Clearing caches'); + Artisan::call('cache:clear'); + Artisan::call('route:clear'); + Artisan::call('config:clear'); + Artisan::call('view:clear'); $this->info('Done!'); } diff --git a/config/modules.php b/config/modules.php index e96331d0..184ece94 100644 --- a/config/modules.php +++ b/config/modules.php @@ -121,7 +121,7 @@ return [ 'cache' => [ 'enabled' => true, 'key' => 'phpvms-modules', - 'lifetime' => 60, + 'lifetime' => 10, ], /* |-------------------------------------------------------------------------- diff --git a/modules/Installer/Http/Controllers/InstallerController.php b/modules/Installer/Http/Controllers/InstallerController.php index bcc49cb3..ca438862 100644 --- a/modules/Installer/Http/Controllers/InstallerController.php +++ b/modules/Installer/Http/Controllers/InstallerController.php @@ -279,7 +279,7 @@ class InstallerController extends Controller { $validator = Validator::make($request->all(), [ 'airline_name' => 'required', - 'airline_icao' => 'required|unique:airlines,icao', + 'airline_icao' => 'required|size:3|unique:airlines,icao', 'airline_country' => 'required', 'name' => 'required', 'email' => 'required|email|unique:users,email',