Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
85.71% |
6 / 7 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| OpenSearchController | |
85.71% |
6 / 7 |
|
0.00% |
0 / 1 |
2.01 | |
0.00% |
0 / 1 |
| index | |
85.71% |
6 / 7 |
|
0.00% |
0 / 1 |
2.01 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * The Administration Elasticsearch Controller |
| 5 | * |
| 6 | * This Source Code Form is subject to the terms of the Mozilla Public License, |
| 7 | * v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 8 | * obtain one at https://mozilla.org/MPL/2.0/. |
| 9 | * |
| 10 | * @package phpMyFAQ |
| 11 | * @author Thorsten Rinne <thorsten@phpmyfaq.de> |
| 12 | * @copyright 2025-2026 phpMyFAQ Team |
| 13 | * @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
| 14 | * @link https://www.phpmyfaq.de |
| 15 | * @since 2025-05-09 |
| 16 | */ |
| 17 | |
| 18 | declare(strict_types=1); |
| 19 | |
| 20 | namespace phpMyFAQ\Controller\Administration; |
| 21 | |
| 22 | use phpMyFAQ\Core\Exception; |
| 23 | use phpMyFAQ\Enums\PermissionType; |
| 24 | use Symfony\Component\HttpFoundation\Request; |
| 25 | use Symfony\Component\HttpFoundation\Response; |
| 26 | use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; |
| 27 | use Symfony\Component\Routing\Attribute\Route; |
| 28 | use Twig\Error\LoaderError; |
| 29 | |
| 30 | final class OpenSearchController extends AbstractAdministrationController |
| 31 | { |
| 32 | /** |
| 33 | * @throws LoaderError |
| 34 | * @throws Exception |
| 35 | */ |
| 36 | #[Route(path: '/opensearch', name: 'admin.opensearch', methods: ['GET'])] |
| 37 | public function index(Request $request): Response |
| 38 | { |
| 39 | $this->userHasPermission(PermissionType::CONFIGURATION_EDIT); |
| 40 | |
| 41 | if (!$this->configuration->get(item: 'search.enableOpenSearch')) { |
| 42 | throw new UnauthorizedHttpException('You are not allowed to access this page.'); |
| 43 | } |
| 44 | |
| 45 | return $this->render('@admin/configuration/opensearch.twig', [ |
| 46 | ...$this->getHeader($request), |
| 47 | ...$this->getFooter(), |
| 48 | ]); |
| 49 | } |
| 50 | } |