From eebb9de5b8029926232ec8b4291bb553b8e11517 Mon Sep 17 00:00:00 2001 From: Arthur Pariente Date: Sun, 8 Oct 2023 17:08:04 +0200 Subject: [PATCH] Maintenance Page (wip) --- app/Filament/Pages/Maintenance.php | 105 ++++++++++++++++++ .../filament/pages/maintenance.blade.php | 62 +++++++++++ 2 files changed, 167 insertions(+) create mode 100644 app/Filament/Pages/Maintenance.php create mode 100644 resources/views/filament/pages/maintenance.blade.php diff --git a/app/Filament/Pages/Maintenance.php b/app/Filament/Pages/Maintenance.php new file mode 100644 index 000000000..0b4ebce3d --- /dev/null +++ b/app/Filament/Pages/Maintenance.php @@ -0,0 +1,105 @@ +label('Force Update Check')->icon('heroicon-o-arrow-path')->action(function () { + app(VersionService::class)->isNewVersionAvailable(); + + $kvpRepo = app(KvpRepository::class); + + $new_version_avail = $kvpRepo->get('new_version_available', false); + $new_version_tag = $kvpRepo->get('latest_version_tag'); + + Log::info('Force check, available='.$new_version_avail.', tag='.$new_version_tag); + + if (!$new_version_avail) { + Notification::make() + ->title('No new version available') + ->success() + ->send(); + } else { + Notification::make() + ->title('New version available: '.$new_version_tag) + ->success() + ->send(); + } + }); + } + + public function webCronEnable(): Action + { + return Action::make('webCronEnable')->label('Enable/Change ID')->action(function () { + $id = Utils::generateNewId(24); + setting_save('cron.random_id', $id); + + Notification::make() + ->title('Web cron refreshed!') + ->success() + ->send(); + }); + } + + public function webCronDisable(): Action + { + return Action::make('webCronDisable')->label('Disable')->color('warning')->action(function () { + setting_save('cron.random_id', ''); + + Notification::make() + ->title('Web cron disabled!') + ->success() + ->send(); + }); + } + + public function clearCaches(): Action + { + return Action::make('clearCaches')->label('Clear Cache')->action(function (array $arguments) { + $calls = []; + $type = $arguments['type']; + + // When clearing the application, clear the config and the app itself + if ($type === 'application' || $type === 'all') { + $calls[] = 'config:cache'; + $calls[] = 'cache:clear'; + $calls[] = 'route:cache'; + $calls[] = 'clear-compiled'; + } + + // If we want to clear only the views but keep everything else + if ($type === 'views' || $type === 'all') { + $calls[] = 'view:clear'; + } + + foreach ($calls as $call) { + Artisan::call($call); + } + + Notification::make() + ->title('Cache cleared!') + ->success() + ->send(); + }); + } +} diff --git a/resources/views/filament/pages/maintenance.blade.php b/resources/views/filament/pages/maintenance.blade.php new file mode 100644 index 000000000..8a530efe0 --- /dev/null +++ b/resources/views/filament/pages/maintenance.blade.php @@ -0,0 +1,62 @@ + + + + Update + + + {{ $this->forceUpdateCheckAction() }} + + + + + CRON + + +
+ A cron must be created that runs every minute calling artisan. An example is below. See the docs +
+ + + + + +
If you don't have cron access on your server, you can use a web-cron service to access this URL every minute. Keep it disabled if you're not using it. It's a unique ID that can be reset/changed if needed for security.
+ + @php + $cron_id = setting('cron.random_id'); + $cron_url = empty($cron_id) ? 'Not enabled' : url(route('api.maintenance.cron', $cron_id)); + @endphp + +
+ + + + +
+ {{ $this->webCronEnable() }} +
+ {{ $this->webCronDisable() }} +
+ +
+ + + + Reset Caches + + +
+ {{ $this->clearCaches()->label('Clear all caches')->arguments(['type' => 'all']) }} + {{ $this->clearCaches()->label('Clear application cache')->arguments(['type' => 'application']) }} + {{ $this->clearCaches()->label('Clear views cache')->arguments(['type' => 'views']) }} +
+
+