Skip to content

Commit 8956d08

Browse files
committed
feat: fetch versions from api.phpmyfaq.de (#2492)
1 parent cb649bc commit 8956d08

File tree

3 files changed

+72
-36
lines changed

3 files changed

+72
-36
lines changed

phpmyfaq/admin/api/updates.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
}

phpmyfaq/admin/api/upgrade.php

Lines changed: 0 additions & 33 deletions
This file was deleted.

phpmyfaq/admin/index.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@
239239
$user->isSuperAdmin())
240240
) {
241241
if (isset($action) && isset($ajax)) {
242-
if ('ajax' === $action) {
242+
if ('ajax' === $action ) {
243243
switch ($ajax) {
244244
// Attachments
245245
case 'att':
@@ -295,8 +295,8 @@
295295
require 'api/image.php';
296296
break;
297297
// Upgrade
298-
case 'upgrade':
299-
require 'api/upgrade.php';
298+
case 'updates':
299+
require 'api/updates.php';
300300
break;
301301
}
302302
exit();

0 commit comments

Comments
 (0)