Forráskód Böngészése

exportRequests datapersister now return resulting file entities

Olivier Massot 3 éve
szülő
commit
10a4045b8b

+ 4 - 5
src/DataPersister/Export/LicenceCmf/ExportRequestDataPersister.php

@@ -36,7 +36,7 @@ class ExportRequestDataPersister implements ContextAwareDataPersisterInterface
      * @return JsonResponse
      * @throws Exception
      */
-    public function persist($exportRequest, array $context = []): JsonResponse
+    public function persist($exportRequest, array $context = []): File
     {
         /** @var Access $access */
         $access = $this->security->getUser();
@@ -52,22 +52,21 @@ class ExportRequestDataPersister implements ContextAwareDataPersisterInterface
         $file->setName('');
         $file->setPath('');
         $file->setSlug('');
+        $file->setIsTemporaryFile(true);
         $this->em->persist($file);
         $this->em->flush();
 
         $exportRequest->setFileId($file->getId());
 
         if (!$exportRequest->isAsync()) {
-            $exportService = $this->handler->getExporterFor($exportRequest);
-            $file = $exportService->export($exportRequest);
-            return new JsonResponse(json_encode(['url' => 'https://my.download.url/' . $file->getId()], JSON_THROW_ON_ERROR), 200);
+            return $this->handler->getExporterFor($exportRequest)->export($exportRequest);
         }
 
         // Send the export request to Messenger (@see App\Message\Handler\ExportHandler)
         $this->messageBus->dispatch(
             new Export($exportRequest)
         );
-        return new JsonResponse('{"message": "Export request has been received (file id: ' . $file->getId() . ')"', 200);
+        return $file;
     }
 
     /**