moduleTemplateFactory->create($request); $view->setTitle('VITEC SSR'); $health = null; $healthError = ''; $endpoint = $this->purgeService->getHealthEndpoint(); if ($endpoint === '') { $healthError = 'var/vitec-ssr-purge.env fehlt oder ist unvollständig.'; } else { $start = microtime(true); try { $response = $this->requestFactory->request($endpoint, 'GET', [ 'timeout' => 3, 'connect_timeout' => 2, 'http_errors' => false, ]); if ($response->getStatusCode() === 200) { $health = json_decode((string)$response->getBody(), true) ?: null; if ($health !== null) { $health['responseMs'] = (int)round((microtime(true) - $start) * 1000); } } else { $healthError = 'HTTP ' . $response->getStatusCode(); } } catch (\Throwable $e) { $healthError = $e->getMessage(); } } $view->assignMultiple([ 'flagOn' => file_exists(Environment::getVarPath() . '/vitec-ssr-on.flag'), 'configured' => $this->purgeService->isConfigured(), 'health' => $health, 'healthError' => $healthError, 'purgeLog' => $this->rows('tx_vitec_ssrpurgelog', 30), 'healthLog' => $this->rows('tx_vitec_ssrhealthlog', 10), 'clientErrors' => $this->clientErrors(50), 'clientErrorCount24h' => $this->clientErrorCount24h(), ]); return $view->renderResponse('Ssr/Index'); } /** * Client error reports of the last 24 hours (POST /api/vitec/client-error, * ClientErrorMiddleware), newest first. Rows carry a "host" (URL without * scheme/query) and a shortened user agent for the table; the full * values stay in the row for the details toggle. */ private function clientErrors(int $limit): array { try { $qb = $this->connectionPool->getQueryBuilderForTable('tx_vitec_clienterrorlog'); $rows = $qb->select('*')->from('tx_vitec_clienterrorlog') ->where($qb->expr()->gt('crdate', $qb->createNamedParameter(time() - 86400, Connection::PARAM_INT))) ->orderBy('uid', 'DESC')->setMaxResults($limit) ->executeQuery()->fetchAllAssociative(); } catch (\Throwable) { return []; } foreach ($rows as &$row) { $path = (string)(parse_url((string)$row['url'], PHP_URL_PATH) ?? ''); $row['path'] = $path !== '' ? $path : (string)$row['url']; $ua = (string)$row['user_agent']; $row['ua_short'] = mb_strlen($ua) > 60 ? mb_substr($ua, 0, 57) . '...' : $ua; $row['is_chunk_reload'] = str_contains(strtolower((string)$row['message']), 'chunk reload'); } unset($row); return $rows; } private function clientErrorCount24h(): int { try { return (int)$this->connectionPool->getConnectionForTable('tx_vitec_clienterrorlog') ->executeQuery('SELECT COUNT(*) FROM tx_vitec_clienterrorlog WHERE crdate > ?', [time() - 86400]) ->fetchOne(); } catch (\Throwable) { return 0; } } public function purgeAction(ServerRequestInterface $request): ResponseInterface { $body = (array)$request->getParsedBody(); $mode = (string)($body['mode'] ?? 'paths'); $user = (string)($GLOBALS['BE_USER']->user['username'] ?? '?'); if ($mode === 'all') { $paths = ['*']; } else { $paths = preg_split('/[\s,]+/', (string)($body['paths'] ?? ''), -1, PREG_SPLIT_NO_EMPTY) ?: []; } if ($paths === []) { $this->flash('No paths given.', 'Purge', false); } else { $result = $this->purgeService->purge($paths, 'module:' . $user); $this->flash( sprintf('HTTP %d — %s', $result['httpCode'], $result['message']), $result['success'] ? 'Purge successful' : 'Purge failed', $result['success'] ); } return new RedirectResponse((string)$this->uriBuilder->buildUriFromRoute('web_vitecssr'), 303); } /** * "Warm cache" button: asks the node to render every page of the * sitemap in the background (0066-FE). Returns at once; progress is * the "Cache warming" row of the status table. */ public function warmAction(ServerRequestInterface $request): ResponseInterface { $result = $this->purgeService->warm(); $this->flash( $result['message'], $result['success'] ? 'Cache warming' : 'Cache warming failed', $result['success'] ); return new RedirectResponse((string)$this->uriBuilder->buildUriFromRoute('web_vitecssr'), 303); } /** * Ajax route vitec_ssr_purge_page: purge exactly one page, called by * the page tree context menu item (ssr-context-menu.js). */ public function purgePage(ServerRequestInterface $request): ResponseInterface { $body = (array)($request->getParsedBody() ?? []); $pageUid = (int)($body['pageUid'] ?? ($request->getQueryParams()['pageUid'] ?? 0)); if ($pageUid <= 0) { return new JsonResponse(['success' => false, 'message' => 'No page uid given'], 400); } try { $site = GeneralUtility::makeInstance(SiteFinder::class)->getSiteByPageId($pageUid); $path = $site->getRouter()->generateUri($pageUid)->getPath() ?: '/'; } catch (\Throwable) { return new JsonResponse(['success' => false, 'message' => 'Page has no routable URL (folder?)']); } $user = (string)($GLOBALS['BE_USER']->user['username'] ?? '?'); $result = $this->purgeService->purge([$path], 'contextmenu:' . $user); return new JsonResponse([ 'success' => $result['success'], 'path' => $path, 'message' => 'HTTP ' . $result['httpCode'] . ' - ' . $result['message'], ]); } private function rows(string $table, int $limit): array { try { $qb = $this->connectionPool->getQueryBuilderForTable($table); return $qb->select('*')->from($table) ->orderBy('uid', 'DESC')->setMaxResults($limit) ->executeQuery()->fetchAllAssociative(); } catch (\Throwable) { return []; } } private function flash(string $message, string $title, bool $ok): void { $flash = GeneralUtility::makeInstance( FlashMessage::class, $message, $title, $ok ? ContextualFeedbackSeverity::OK : ContextualFeedbackSeverity::ERROR, true ); $this->flashMessageService->getMessageQueueByIdentifier()->addMessage($flash); } }