-
-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): added basic controller für update API (#3313)
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
/** | ||
* The Update Controller for the REST API | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* @package phpMyFAQ | ||
* @author Thorsten Rinne <thorsten@phpmyfaq.de> | ||
* @copyright 2025 phpMyFAQ Team | ||
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 | ||
* @link https://www.phpmyfaq.de | ||
* @since 2025-01-06 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace phpMyFAQ\Controller\Api; | ||
|
||
use OpenApi\Attributes as OA; | ||
use phpMyFAQ\Controller\AbstractController; | ||
use phpMyFAQ\Enums\PermissionType; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; | ||
|
||
class UpdateController extends AbstractController | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
|
||
if (!$this->isApiEnabled()) { | ||
throw new UnauthorizedHttpException('API is not enabled'); | ||
} | ||
} | ||
|
||
#[OA\Post(path: '/api/v3.1/update', operationId: 'triggerUpdate', tags: ['Endpoints with Authentication'])] | ||
#[OA\Header( | ||
header: 'x-pmf-token', | ||
description: 'phpMyFAQ client API Token, generated in admin backend', | ||
schema: new OA\Schema(type: 'string') | ||
)] | ||
#[OA\Response( | ||
response: 200, | ||
description: 'Returns the new and updated phpMyFAQ version number as string.', | ||
content: new OA\JsonContent(example: '4.0.0'), | ||
)] | ||
#[OA\Response( | ||
response: 401, | ||
description: 'If the user is not authenticated and/or does not have sufficient permissions.' | ||
)] | ||
public function index(): Response | ||
{ | ||
$this->userHasPermission(PermissionType::CONFIGURATION_EDIT); | ||
|
||
return $this->json($this->configuration->getVersion()); | ||
} | ||
} |