|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Private phpMyFAQ Admin API: everything for the online update |
| 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 <[email protected]> |
| 12 | + * @copyright 2023 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 2023-07-02 |
| 16 | + */ |
| 17 | + |
| 18 | +use phpMyFAQ\Filter; |
| 19 | +use Symfony\Component\HttpClient\HttpClient; |
| 20 | +use Symfony\Component\HttpFoundation\JsonResponse; |
| 21 | +use Symfony\Component\HttpFoundation\Request; |
| 22 | +use Symfony\Component\HttpFoundation\Response; |
| 23 | +use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; |
| 24 | + |
| 25 | +if (!defined('IS_VALID_PHPMYFAQ')) { |
| 26 | + http_response_code(400); |
| 27 | + exit(); |
| 28 | +} |
| 29 | + |
| 30 | +// |
| 31 | +// Create Request & Response |
| 32 | +// |
| 33 | +$response = new JsonResponse(); |
| 34 | +$request = Request::createFromGlobals(); |
| 35 | + |
| 36 | +$ajaxAction = Filter::filterVar($request->query->get('ajaxaction'), FILTER_SANITIZE_SPECIAL_CHARS); |
| 37 | + |
| 38 | +/* |
| 39 | + * API |
| 40 | + * Retrieve Available Updates |
| 41 | + * - GET /updates: Returns a list of available updates. |
| 42 | + * - GET /updates/{version}: Retrieves information about a specific update. |
| 43 | + * |
| 44 | + * Apply Updates |
| 45 | + * - POST /updates/{version}/apply: Applies a specific update identified by its ID. |
| 46 | + * |
| 47 | + * Progress |
| 48 | + * - GET /updates/{version}/progress: Retrieves information about the progress of the update |
| 49 | + */ |
| 50 | + |
| 51 | +switch ($ajaxAction) { |
| 52 | + // GET /updates: Returns a list of available updates. |
| 53 | + default: |
| 54 | + $client = HttpClient::create(); |
| 55 | + try { |
| 56 | + $versions = $client->request( |
| 57 | + 'GET', |
| 58 | + 'https://api.phpmyfaq.de/versions' |
| 59 | + ); |
| 60 | + $response->setStatusCode(Response::HTTP_OK); |
| 61 | + $response->setContent($versions->getContent()); |
| 62 | + $response->send(); |
| 63 | + } catch (TransportExceptionInterface $e) { |
| 64 | + $response->setStatusCode(Response::HTTP_BAD_REQUEST); |
| 65 | + $response->setData($e->getMessage()); |
| 66 | + $response->send(); |
| 67 | + } |
| 68 | + break; |
| 69 | +} |
0 commit comments