diff --git a/src/EventSubscriber/ImageRepositorySubscriber.php b/src/EventSubscriber/ImageRepositorySubscriber.php new file mode 100644 index 0000000..41f6f1b --- /dev/null +++ b/src/EventSubscriber/ImageRepositorySubscriber.php @@ -0,0 +1,60 @@ + ['transferImages', EventPriorities::POST_WRITE], + ]; + } + + /** + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + * @throws RedirectionExceptionInterface + * @throws ClientExceptionInterface + */ + public function transferImages(ViewEvent $event): void + { + $imageRepositoryOutput = $event->getControllerResult(); + $method = $event->getRequest()->getMethod(); + + if (!$imageRepositoryOutput instanceof ImageRepositoryOutput || + $method != Request::METHOD_POST) { + return; + } + + $imagesToImport = $this->entityManager->getRepository(Image::class)->findBy(['isGlobal' => true]); + + foreach($imagesToImport as $imageToImport) { + $this->transferIsGlobalAction->__invoke([$imageToImport], $imageRepositoryOutput->getEntity()); + } + } +} \ No newline at end of file