Skip to content

Commit

Permalink
Installer: Shows errors on submit & move runMigrations (#722)
Browse files Browse the repository at this point in the history
* catch Halt exception to make sure error notifications are displayed

* run migrations on submit to make sure the correct data is used
  • Loading branch information
Boy132 authored Dec 1, 2024
1 parent cd448cd commit e0c6137
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
31 changes: 17 additions & 14 deletions app/Filament/Pages/Installer/PanelInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions app/Filament/Pages/Installer/Steps/DatabaseStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ public static function make(PanelInstaller $installer): Step
}

$installer->writeToEnv('env_database');

$installer->runMigrations($driver);
});
}

Expand Down
4 changes: 1 addition & 3 deletions app/Filament/Pages/Installer/Steps/QueueStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}

0 comments on commit e0c6137

Please sign in to comment.