diff --git a/src/EventSubscriber/MaintenanceModeSubscriber.php b/src/EventSubscriber/MaintenanceModeSubscriber.php index 74b219a0..6efa975e 100644 --- a/src/EventSubscriber/MaintenanceModeSubscriber.php +++ b/src/EventSubscriber/MaintenanceModeSubscriber.php @@ -37,8 +37,7 @@ use Twig\Environment; */ readonly class MaintenanceModeSubscriber implements EventSubscriberInterface { - public function __construct(private UpdateExecutor $updateExecutor, - private Environment $twig) + public function __construct(private UpdateExecutor $updateExecutor) { } @@ -48,7 +47,6 @@ readonly class MaintenanceModeSubscriber implements EventSubscriberInterface return [ // High priority to run before other listeners KernelEvents::REQUEST => ['onKernelRequest', 512], //High priority to run before other listeners - KernelEvents::RESPONSE => ['onKernelResponse', -512] // Low priority to run after other listeners ]; } @@ -71,13 +69,12 @@ readonly class MaintenanceModeSubscriber implements EventSubscriberInterface // Get maintenance info $maintenanceInfo = $this->updateExecutor->getMaintenanceInfo(); - $lockInfo = $this->updateExecutor->getLockInfo(); // Calculate how long the update has been running $duration = null; - if ($lockInfo && isset($lockInfo['started_at'])) { + if ($maintenanceInfo && isset($maintenanceInfo['enabled_at'])) { try { - $startedAt = new \DateTime($lockInfo['started_at']); + $startedAt = new \DateTime($maintenanceInfo['enabled_at']); $now = new \DateTime(); $duration = $now->getTimestamp() - $startedAt->getTimestamp(); } catch (\Exception) { @@ -85,17 +82,7 @@ readonly class MaintenanceModeSubscriber implements EventSubscriberInterface } } - // Try to render the Twig template, fall back to simple HTML - try { - $content = $this->twig->render('maintenance/maintenance.html.twig', [ - 'reason' => $maintenanceInfo['reason'] ?? 'Maintenance in progress', - 'started_at' => $maintenanceInfo['enabled_at'] ?? null, - 'duration' => $duration, - ]); - } catch (\Exception) { - // Fallback to simple HTML if Twig fails - $content = $this->getSimpleMaintenanceHtml($maintenanceInfo, $duration); - } + $content = $this->getSimpleMaintenanceHtml($maintenanceInfo, $duration); $response = new Response($content, Response::HTTP_SERVICE_UNAVAILABLE); $response->headers->set('Retry-After', '30'); @@ -104,28 +91,6 @@ readonly class MaintenanceModeSubscriber implements EventSubscriberInterface $event->setResponse($response); } - public function onKernelResponse(ResponseEvent $event) - { - // Only handle main requests - if (!$event->isMainRequest()) { - return; - } - - // Skip if not in maintenance mode - if (!$this->updateExecutor->isMaintenanceMode()) { - return; - } - - // Allow CLI requests - if (PHP_SAPI === 'cli') { - return; - } - - //Remove all Content-Security-Policy headers to allow loading resources during maintenance - $response = $event->getResponse(); - $response->headers->remove('Content-Security-Policy'); - } - /** * Generate a simple maintenance page HTML without Twig. */ @@ -134,6 +99,8 @@ readonly class MaintenanceModeSubscriber implements EventSubscriberInterface $reason = htmlspecialchars($maintenanceInfo['reason'] ?? 'Update in progress'); $durationText = $duration !== null ? sprintf('%d seconds', $duration) : 'a moment'; + $startDateStr = $maintenanceInfo['enabled_at'] ?? 'unknown time'; + return << @@ -233,7 +200,7 @@ readonly class MaintenanceModeSubscriber implements EventSubscriberInterface
⚙️
-

Part-DB is Updating

+

Part-DB is under maintenance

We're making things better. This should only take a moment.

@@ -245,7 +212,9 @@ readonly class MaintenanceModeSubscriber implements EventSubscriberInterface

- Update running for {$durationText}
+ Maintenance mode active since {$startDateStr}
+
+ Started {$durationText} ago
This page will automatically refresh every 15 seconds.

diff --git a/templates/maintenance/maintenance.html.twig b/templates/maintenance/maintenance.html.twig deleted file mode 100644 index 05cab1cf..00000000 --- a/templates/maintenance/maintenance.html.twig +++ /dev/null @@ -1,251 +0,0 @@ - - - - - - - Part-DB - {% trans %}update_manager.maintenance.title{% endtrans %} - - - - - -
-
- -
- -

{% trans %}update_manager.maintenance.heading{% endtrans %}

- -

- {% trans %}update_manager.maintenance.description{% endtrans %} -

- -
- - {{ reason }} -
- -
-
-
-
-
- -
-
- - {% trans %}update_manager.maintenance.step_backup{% endtrans %} -
-
- - {% trans %}update_manager.maintenance.step_download{% endtrans %} -
-
- - {% trans %}update_manager.maintenance.step_install{% endtrans %} -
-
- - {% trans %}update_manager.maintenance.step_migrate{% endtrans %} -
-
- - {% trans %}update_manager.maintenance.step_cache{% endtrans %} -
-
- - {% if duration is not null %} -
- {{ duration // 60 }}:{{ '%02d'|format(duration % 60) }} -
- {% endif %} - -

- - {% trans %}update_manager.maintenance.auto_refresh{% endtrans %} -

- - -
- - - - diff --git a/translations/messages.en.xlf b/translations/messages.en.xlf index b6537a5f..c9167bd4 100644 --- a/translations/messages.en.xlf +++ b/translations/messages.en.xlf @@ -14718,60 +14718,6 @@ Buerklin-API Authentication server: bytes - - - update_manager.maintenance.title - Maintenance - - - - - update_manager.maintenance.heading - Part-DB is Updating - - - - - update_manager.maintenance.description - We're installing updates to make Part-DB even better. This should only take a moment. - - - - - update_manager.maintenance.step_backup - Creating backup - - - - - update_manager.maintenance.step_download - Downloading updates - - - - - update_manager.maintenance.step_install - Installing files - - - - - update_manager.maintenance.step_migrate - Running migrations - - - - - update_manager.maintenance.step_cache - Clearing cache - - - - - update_manager.maintenance.auto_refresh - This page will refresh automatically when the update is complete. - - perm.system.manage_updates