@@ -40,14 +40,14 @@ discard block |
||
| 40 | 40 | use FOS\RestBundle\Controller\Annotations\Route; |
| 41 | 41 | |
| 42 | 42 | class ContentPushController extends AbstractController { |
| 43 | - private EventDispatcherInterface $eventDispatcher; |
|
| 44 | - private FormFactoryInterface $formFactory; |
|
| 45 | - private MessageBusInterface $messageBus;//swp_multi_tenancy.tenant_context |
|
| 46 | - private DataTransformerInterface $dataTransformer; // swp_bridge.transformer.json_to_package |
|
| 47 | - private MediaManagerInterface $mediaManager; // swp_content_bundle.manager.media |
|
| 48 | - private EntityManagerInterface $entityManager; // swp.object_manager.media |
|
| 49 | - private PackageRepository $packageRepository;//swp.repository.package |
|
| 50 | - private FileProviderInterface $fileProvider; |
|
| 43 | + private EventDispatcherInterface $eventDispatcher; |
|
| 44 | + private FormFactoryInterface $formFactory; |
|
| 45 | + private MessageBusInterface $messageBus;//swp_multi_tenancy.tenant_context |
|
| 46 | + private DataTransformerInterface $dataTransformer; // swp_bridge.transformer.json_to_package |
|
| 47 | + private MediaManagerInterface $mediaManager; // swp_content_bundle.manager.media |
|
| 48 | + private EntityManagerInterface $entityManager; // swp.object_manager.media |
|
| 49 | + private PackageRepository $packageRepository;//swp.repository.package |
|
| 50 | + private FileProviderInterface $fileProvider; |
|
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * @param EventDispatcherInterface $eventDispatcher |
@@ -59,11 +59,11 @@ discard block |
||
| 59 | 59 | * @param PackageRepository $packageRepository |
| 60 | 60 | * @param FileProviderInterface $fileProvider |
| 61 | 61 | */ |
| 62 | - public function __construct(EventDispatcherInterface $eventDispatcher, FormFactoryInterface $formFactory, |
|
| 63 | - MessageBusInterface $messageBus, |
|
| 64 | - DataTransformerInterface $dataTransformer, MediaManagerInterface $mediaManager, |
|
| 65 | - EntityManagerInterface $entityManager, PackageRepository $packageRepository, |
|
| 66 | - FileProviderInterface $fileProvider) { |
|
| 62 | + public function __construct(EventDispatcherInterface $eventDispatcher, FormFactoryInterface $formFactory, |
|
| 63 | + MessageBusInterface $messageBus, |
|
| 64 | + DataTransformerInterface $dataTransformer, MediaManagerInterface $mediaManager, |
|
| 65 | + EntityManagerInterface $entityManager, PackageRepository $packageRepository, |
|
| 66 | + FileProviderInterface $fileProvider) { |
|
| 67 | 67 | $this->eventDispatcher = $eventDispatcher; |
| 68 | 68 | $this->formFactory = $formFactory; |
| 69 | 69 | $this->messageBus = $messageBus; |
@@ -72,13 +72,13 @@ discard block |
||
| 72 | 72 | $this->entityManager = $entityManager; |
| 73 | 73 | $this->packageRepository = $packageRepository; |
| 74 | 74 | $this->fileProvider = $fileProvider; |
| 75 | - } |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * @Route("/api/{version}/content/push", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_push") |
|
| 80 | - */ |
|
| 81 | - public function pushContentAction(Request $request, TenantContextInterface $tenantContext): SingleResourceResponseInterface { |
|
| 78 | + /** |
|
| 79 | + * @Route("/api/{version}/content/push", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_push") |
|
| 80 | + */ |
|
| 81 | + public function pushContentAction(Request $request, TenantContextInterface $tenantContext): SingleResourceResponseInterface { |
|
| 82 | 82 | $package = $this->dataTransformer->transform($request->getContent()); |
| 83 | 83 | $this->eventDispatcher->dispatch(new GenericEvent($package), Events::SWP_VALIDATION); |
| 84 | 84 | |
@@ -87,27 +87,27 @@ discard block |
||
| 87 | 87 | $this->messageBus->dispatch(new ContentPushMessage($currentTenant->getId(), $request->getContent())); |
| 88 | 88 | |
| 89 | 89 | return new SingleResourceResponse(['status' => 'OK'], new ResponseContext(201)); |
| 90 | - } |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * @Route("/api/{version}/assets/push", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_assets_push") |
|
| 94 | - */ |
|
| 95 | - public function pushAssetsAction(Request $request): SingleResourceResponseInterface { |
|
| 92 | + /** |
|
| 93 | + * @Route("/api/{version}/assets/push", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_assets_push") |
|
| 94 | + */ |
|
| 95 | + public function pushAssetsAction(Request $request): SingleResourceResponseInterface { |
|
| 96 | 96 | $form = $this->formFactory->createNamed('', MediaFileType::class); |
| 97 | 97 | $form->handleRequest($request); |
| 98 | 98 | |
| 99 | 99 | if ($form->isSubmitted() && $form->isValid()) { |
| 100 | - $mediaManager = $this->mediaManager; |
|
| 101 | - $uploadedFile = $form->getData()['media']; |
|
| 102 | - $mediaId = $request->request->get('mediaId'); |
|
| 100 | + $mediaManager = $this->mediaManager; |
|
| 101 | + $uploadedFile = $form->getData()['media']; |
|
| 102 | + $mediaId = $request->request->get('mediaId'); |
|
| 103 | 103 | |
| 104 | - if ($uploadedFile->isValid()) { |
|
| 104 | + if ($uploadedFile->isValid()) { |
|
| 105 | 105 | $fileProvider = $this->fileProvider; |
| 106 | 106 | $file = $fileProvider->getFile(ArticleMedia::handleMediaId($mediaId), $uploadedFile->guessExtension()); |
| 107 | 107 | |
| 108 | 108 | if (null === $file) { |
| 109 | - $file = $mediaManager->handleUploadedFile($uploadedFile, $mediaId); |
|
| 110 | - $this->entityManager->flush(); |
|
| 109 | + $file = $mediaManager->handleUploadedFile($uploadedFile, $mediaId); |
|
| 110 | + $this->entityManager->flush(); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | return new SingleResourceResponse( |
@@ -120,23 +120,23 @@ discard block |
||
| 120 | 120 | ], |
| 121 | 121 | new ResponseContext(201) |
| 122 | 122 | ); |
| 123 | - } |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - throw new \Exception('Uploaded file is not valid:' . $uploadedFile->getErrorMessage()); |
|
| 125 | + throw new \Exception('Uploaded file is not valid:' . $uploadedFile->getErrorMessage()); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | return new SingleResourceResponse($form); |
| 129 | - } |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * @Route("/api/{version}/assets/{action}/{mediaId}.{extension}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, requirements={"mediaId"=".+", "action"="get|push"}, name="swp_api_assets_get") |
|
| 133 | - */ |
|
| 134 | - public function getAssetsAction(string $mediaId, string $extension): SingleResourceResponseInterface { |
|
| 131 | + /** |
|
| 132 | + * @Route("/api/{version}/assets/{action}/{mediaId}.{extension}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, requirements={"mediaId"=".+", "action"="get|push"}, name="swp_api_assets_get") |
|
| 133 | + */ |
|
| 134 | + public function getAssetsAction(string $mediaId, string $extension): SingleResourceResponseInterface { |
|
| 135 | 135 | $fileProvider = $this->fileProvider; |
| 136 | 136 | $file = $fileProvider->getFile(ArticleMedia::handleMediaId($mediaId), $extension); |
| 137 | 137 | |
| 138 | 138 | if (null === $file) { |
| 139 | - throw new NotFoundHttpException('Media don\'t exist in storage'); |
|
| 139 | + throw new NotFoundHttpException('Media don\'t exist in storage'); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | $mediaManager = $this->mediaManager; |
@@ -148,9 +148,9 @@ discard block |
||
| 148 | 148 | 'mime_type' => Mime::getMimeFromExtension($file->getFileExtension()), |
| 149 | 149 | 'filemeta' => [], |
| 150 | 150 | ]); |
| 151 | - } |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - protected function getPackageRepository() { |
|
| 153 | + protected function getPackageRepository() { |
|
| 154 | 154 | return $this->packageRepository; |
| 155 | - } |
|
| 155 | + } |
|
| 156 | 156 | } |