|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | + |
| 4 | +/** |
| 5 | + * This source file is available under the terms of the |
| 6 | + * Pimcore Open Core License (POCL) |
| 7 | + * Full copyright and license information is available in |
| 8 | + * LICENSE.md which is distributed with this source code. |
| 9 | + * |
| 10 | + * @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com) |
| 11 | + * @license Pimcore Open Core License (POCL) |
| 12 | + */ |
| 13 | + |
| 14 | +namespace Pimcore\Bundle\DataHubBundle\Controller\Studio\Config; |
| 15 | + |
| 16 | +use Exception; |
| 17 | +use OpenApi\Attributes\JsonContent; |
| 18 | +use OpenApi\Attributes\Put; |
| 19 | +use OpenApi\Attributes\RequestBody; |
| 20 | +use OpenApi\Attributes\Schema; |
| 21 | +use Pimcore\Bundle\DataHubBundle\OpenApi\Config\Prefix; |
| 22 | +use Pimcore\Bundle\DataHubBundle\OpenApi\Config\Tags; |
| 23 | +use Pimcore\Bundle\DataHubBundle\Schema\UpdateConfiguration; |
| 24 | +use Pimcore\Bundle\DataHubBundle\Schema\UpdateConfigurationResponse; |
| 25 | +use Pimcore\Bundle\DataHubBundle\Service\Studio\ConfigurationServiceInterface; |
| 26 | +use Pimcore\Bundle\DataHubBundle\Utils\Constants\PermissionConstants; |
| 27 | +use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; |
| 28 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\IdParameter; |
| 29 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses; |
| 30 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse; |
| 31 | +use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes; |
| 32 | +use Symfony\Component\HttpFoundation\JsonResponse; |
| 33 | +use Symfony\Component\HttpKernel\Attribute\MapRequestPayload; |
| 34 | +use Symfony\Component\Routing\Attribute\Route; |
| 35 | +use Symfony\Component\Security\Http\Attribute\IsGranted; |
| 36 | +use Symfony\Component\Serializer\SerializerInterface; |
| 37 | + |
| 38 | +/** |
| 39 | + * @internal |
| 40 | + */ |
| 41 | +final class UpdateController extends AbstractApiController |
| 42 | +{ |
| 43 | + private const string ROUTE = '/config/{name}'; |
| 44 | + |
| 45 | + public function __construct( |
| 46 | + SerializerInterface $serializer, |
| 47 | + private readonly ConfigurationServiceInterface $configurationService |
| 48 | + ) { |
| 49 | + parent::__construct($serializer); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * @throws Exception |
| 54 | + */ |
| 55 | + #[Route( |
| 56 | + path: self::ROUTE, |
| 57 | + name: 'pimcore_studio_api_data_hub_config_update', |
| 58 | + methods: ['PUT'] |
| 59 | + )] |
| 60 | + #[Put( |
| 61 | + path: Prefix::BUNDLE . self::ROUTE, |
| 62 | + operationId: 'bundle_data_hub_config_update', |
| 63 | + description: 'bundle_data_hub_config_update_description', |
| 64 | + summary: 'bundle_data_hub_config_update_summary', |
| 65 | + tags: [Tags::DataHub->value] |
| 66 | + )] |
| 67 | + #[IdParameter( |
| 68 | + type: 'configuration', |
| 69 | + schema: new Schema(type: 'string'), |
| 70 | + name: 'name', |
| 71 | + )] |
| 72 | + #[RequestBody( |
| 73 | + required: true, |
| 74 | + content: new JsonContent(ref: UpdateConfiguration::class) |
| 75 | + )] |
| 76 | + #[SuccessResponse( |
| 77 | + description: 'bundle_data_hub_config_update_success_response', |
| 78 | + content: new JsonContent(ref: UpdateConfigurationResponse::class) |
| 79 | + )] |
| 80 | + #[IsGranted(PermissionConstants::PLUGIN_DATA_HUB_CONFIG)] |
| 81 | + #[DefaultResponses([ |
| 82 | + HttpResponseCodes::UNAUTHORIZED, |
| 83 | + HttpResponseCodes::NOT_FOUND, |
| 84 | + HttpResponseCodes::CONFLICT, |
| 85 | + ])] |
| 86 | + public function updateConfiguration( |
| 87 | + string $name, |
| 88 | + #[MapRequestPayload] UpdateConfiguration $updateConfiguration |
| 89 | + ): JsonResponse { |
| 90 | + $modificationDate = $this->configurationService->updateConfiguration( |
| 91 | + $name, |
| 92 | + $updateConfiguration->getConfiguration(), |
| 93 | + $updateConfiguration->getModificationDate() |
| 94 | + ); |
| 95 | + |
| 96 | + return $this->jsonResponse( |
| 97 | + new UpdateConfigurationResponse($modificationDate) |
| 98 | + ); |
| 99 | + } |
| 100 | +} |
| 101 | + |
0 commit comments