|
| 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\StudioBackendBundle\Class\Controller\BulkExport; |
| 15 | + |
| 16 | +use OpenApi\Attributes\Post; |
| 17 | +use Pimcore\Bundle\StudioBackendBundle\Class\MappedParameter\BulkExportParameters; |
| 18 | +use Pimcore\Bundle\StudioBackendBundle\Class\Service\BulkExport\BulkExportServiceInterface; |
| 19 | +use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; |
| 20 | +use Pimcore\Bundle\StudioBackendBundle\Exception\Api\EnvironmentException; |
| 21 | +use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; |
| 22 | +use Pimcore\Bundle\StudioBackendBundle\Exception\Api\UserNotFoundException; |
| 23 | +use Pimcore\Bundle\StudioBackendBundle\Export\Service\DownloadServiceInterface; |
| 24 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Request\ReferenceRequestBody; |
| 25 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\MediaType; |
| 26 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses; |
| 27 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Header\ContentDisposition; |
| 28 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse; |
| 29 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; |
| 30 | +use Pimcore\Bundle\StudioBackendBundle\Util\Constant\Asset\MimeTypes; |
| 31 | +use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes; |
| 32 | +use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions; |
| 33 | +use Symfony\Component\HttpFoundation\Response; |
| 34 | +use Symfony\Component\HttpKernel\Attribute\MapRequestPayload; |
| 35 | +use Symfony\Component\Routing\Attribute\Route; |
| 36 | +use Symfony\Component\Security\Http\Attribute\IsGranted; |
| 37 | +use Symfony\Component\Serializer\SerializerInterface; |
| 38 | + |
| 39 | +/** |
| 40 | + * @internal |
| 41 | + */ |
| 42 | +final class ExportController extends AbstractApiController |
| 43 | +{ |
| 44 | + private const string ROUTE = '/class/bulk-export'; |
| 45 | + |
| 46 | + public function __construct( |
| 47 | + SerializerInterface $serializer, |
| 48 | + private readonly BulkExportServiceInterface $bulkExportService, |
| 49 | + private readonly DownloadServiceInterface $downloadService, |
| 50 | + ) { |
| 51 | + parent::__construct($serializer); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * @throws EnvironmentException|NotFoundException|UserNotFoundException |
| 56 | + */ |
| 57 | + #[Route( |
| 58 | + path: self::ROUTE, |
| 59 | + name: 'pimcore_studio_api_class_bulk_export', |
| 60 | + methods: ['POST'], |
| 61 | + )] |
| 62 | + #[IsGranted(UserPermissions::DATA_OBJECTS->value)] |
| 63 | + #[Post( |
| 64 | + path: self::PREFIX . self::ROUTE, |
| 65 | + operationId: 'class_bulk_export', |
| 66 | + description: 'class_bulk_export_description', |
| 67 | + summary: 'class_bulk_export_summary', |
| 68 | + tags: [Tags::ClassDefinition->value], |
| 69 | + )] |
| 70 | + #[ReferenceRequestBody(BulkExportParameters::class)] |
| 71 | + #[SuccessResponse( |
| 72 | + description: 'class_bulk_export_success_response', |
| 73 | + content: [new MediaType(MimeTypes::JSON->value)], |
| 74 | + headers: [new ContentDisposition(fileName: 'bulk_export.json')] |
| 75 | + )] |
| 76 | + #[DefaultResponses([ |
| 77 | + HttpResponseCodes::UNAUTHORIZED, |
| 78 | + HttpResponseCodes::NOT_FOUND, |
| 79 | + ])] |
| 80 | + public function exportItems( |
| 81 | + #[MapRequestPayload] BulkExportParameters $parameters |
| 82 | + ): Response { |
| 83 | + $export = $this->bulkExportService->exportItems($parameters); |
| 84 | + |
| 85 | + return $this->downloadService->downloadJSON( |
| 86 | + $export->getJson(), |
| 87 | + $export->getFileName() |
| 88 | + ); |
| 89 | + } |
| 90 | +} |
0 commit comments