From e0c6137b92cce20184dbb910581a1dfaf3ef2489 Mon Sep 17 00:00:00 2001 From: Boy132 Date: Sun, 1 Dec 2024 04:04:40 +0100 Subject: [PATCH] Installer: Shows errors on submit & move `runMigrations` (#722) * catch Halt exception to make sure error notifications are displayed * run migrations on submit to make sure the correct data is used --- .../Pages/Installer/PanelInstaller.php | 31 ++++++++++--------- .../Pages/Installer/Steps/DatabaseStep.php | 2 -- .../Pages/Installer/Steps/QueueStep.php | 4 +-- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/app/Filament/Pages/Installer/PanelInstaller.php b/app/Filament/Pages/Installer/PanelInstaller.php index bad77920d0..44b6ee58b6 100644 --- a/app/Filament/Pages/Installer/PanelInstaller.php +++ b/app/Filament/Pages/Installer/PanelInstaller.php @@ -23,8 +23,6 @@ use Filament\Pages\SimplePage; use Filament\Support\Enums\MaxWidth; use Filament\Support\Exceptions\Halt; -use Illuminate\Http\RedirectResponse; -use Illuminate\Routing\Redirector; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Blade; use Illuminate\Support\HtmlString; @@ -91,20 +89,26 @@ protected function getFormStatePath(): ?string return 'data'; } - public function submit(UserCreationService $userCreationService): Redirector|RedirectResponse + public function submit(UserCreationService $userCreationService): void { - // Disable installer - $this->writeToEnvironment(['APP_INSTALLED' => 'true']); + try { + // Disable installer + $this->writeToEnvironment(['APP_INSTALLED' => 'true']); + + // Run migrations + $this->runMigrations(); - // Create admin user & login - $user = $this->createAdminUser($userCreationService); - auth()->guard()->login($user, true); + // Create admin user & login + $user = $this->createAdminUser($userCreationService); + auth()->guard()->login($user, true); - // Write session data at the very end to avoid "page expired" errors - $this->writeToEnv('env_session'); + // Write session data at the very end to avoid "page expired" errors + $this->writeToEnv('env_session'); - // Redirect to admin panel - return redirect(Dashboard::getUrl()); + // Redirect to admin panel + $this->redirect(Dashboard::getUrl()); + } catch (Halt) { + } } public function writeToEnv(string $key): void @@ -129,13 +133,12 @@ public function writeToEnv(string $key): void Artisan::call('config:clear'); } - public function runMigrations(string $driver): void + public function runMigrations(): void { try { Artisan::call('migrate', [ '--force' => true, '--seed' => true, - '--database' => $driver, ]); } catch (Exception $exception) { report($exception); diff --git a/app/Filament/Pages/Installer/Steps/DatabaseStep.php b/app/Filament/Pages/Installer/Steps/DatabaseStep.php index 7ddae24f02..0bcf88f8b8 100644 --- a/app/Filament/Pages/Installer/Steps/DatabaseStep.php +++ b/app/Filament/Pages/Installer/Steps/DatabaseStep.php @@ -97,8 +97,6 @@ public static function make(PanelInstaller $installer): Step } $installer->writeToEnv('env_database'); - - $installer->runMigrations($driver); }); } diff --git a/app/Filament/Pages/Installer/Steps/QueueStep.php b/app/Filament/Pages/Installer/Steps/QueueStep.php index 4e6c065d0e..d87b3f1528 100644 --- a/app/Filament/Pages/Installer/Steps/QueueStep.php +++ b/app/Filament/Pages/Installer/Steps/QueueStep.php @@ -57,8 +57,6 @@ public static function make(PanelInstaller $installer): Step ->hidden(fn () => file_exists('/.dockerenv')) ->columnSpanFull(), ]) - ->afterValidation(function () use ($installer) { - $installer->writeToEnv('env_queue'); - }); + ->afterValidation(fn () => $installer->writeToEnv('env_queue')); } }