1717use OpenApi \Attributes \Property ;
1818use Pimcore \Bundle \StudioBackendBundle \Asset \Service \ExecutionEngine \ZipServiceInterface ;
1919use Pimcore \Bundle \StudioBackendBundle \Controller \AbstractApiController ;
20- use Pimcore \Bundle \StudioBackendBundle \Exception \Api \EnvironmentException ;
2120use Pimcore \Bundle \StudioBackendBundle \Exception \Api \ForbiddenException ;
2221use Pimcore \Bundle \StudioBackendBundle \Exception \Api \NotFoundException ;
2322use Pimcore \Bundle \StudioBackendBundle \Exception \Api \UserNotFoundException ;
3332use Pimcore \Bundle \StudioBackendBundle \Util \Constant \UserPermissions ;
3433use Symfony \Component \HttpFoundation \File \UploadedFile ;
3534use Symfony \Component \HttpFoundation \JsonResponse ;
36- use Symfony \Component \HttpFoundation \ Request ;
35+ use Symfony \Component \HttpKernel \ Attribute \ MapUploadedFile ;
3736use Symfony \Component \Routing \Attribute \Route ;
3837use Symfony \Component \Security \Http \Attribute \IsGranted ;
3938use Symfony \Component \Serializer \SerializerInterface ;
4342 */
4443final class ZipController extends AbstractApiController
4544{
46- private const FILE_KEY = 'zipFile ' ;
47-
4845 public function __construct (
4946 private readonly SecurityServiceInterface $ securityService ,
5047 private readonly ZipServiceInterface $ zipService ,
@@ -54,7 +51,6 @@ public function __construct(
5451 }
5552
5653 /**
57- * @throws EnvironmentException
5854 * @throws ForbiddenException
5955 * @throws NotFoundException
6056 * @throws UserNotFoundException
@@ -76,13 +72,13 @@ public function __construct(
7672 #[MultipartFormDataRequestBody(
7773 [
7874 new Property (
79- property: self :: FILE_KEY ,
75+ property: ' zipFile ' ,
8076 description: 'Zip file to upload ' ,
8177 type: 'string ' ,
8278 format: 'binary '
8379 ),
8480 ],
85- [self :: FILE_KEY ]
81+ [' zipFile ' ]
8682 )]
8783 #[DefaultResponses([
8884 HttpResponseCodes::FORBIDDEN ,
@@ -91,19 +87,14 @@ public function __construct(
9187 ])]
9288 public function addAssetsZip (
9389 int $ parentId ,
94- // TODO: Symfony 7.1 change to https://symfony.com/blog/new-in-symfony-7-1-mapuploadedfile-attribute
95- Request $ request
90+ #[MapUploadedFile(name: 'zipFile ' )] UploadedFile $ zipFile ,
9691 ): JsonResponse {
97- $ file = $ request ->files ->get (self ::FILE_KEY );
98- if (!$ file instanceof UploadedFile) {
99- throw new EnvironmentException ('Invalid zip file found in the request ' );
100- }
10192
10293 return $ this ->jsonResponse (
10394 [
10495 'jobRunId ' => $ this ->zipService ->uploadZipAssets (
10596 $ this ->securityService ->getCurrentUser (),
106- $ file ,
97+ $ zipFile ,
10798 $ parentId
10899 ),
109100 ]
0 commit comments