ImportExportMessage example

$progress = new Progress($logEntity->getId()$logEntity->getState());

        $importExport = $this->createMock(ImportExport::class);
        $importExport->method('import')
            ->willReturn($progress);
        $importExport->method('getLogEntity')
            ->willReturn($logEntity);

        $factory->method('create')
            ->willReturn($importExport);

        $importExportMessage = new ImportExportMessage($context$logEntity->getId()$logEntity->getActivity());

        $importExportHandler->__invoke($importExportMessage);

        $messages = $messageBus->getMessages();

        $importExportMessage = null;
        /** @var Envelope $message */
        foreach ($messages as $message) {
            if ($message->getMessage() instanceof ImportExportMessage) {
                $importExportMessage = $message->getMessage();
            }
        }
$logEntity->getActivity() === ImportExportLogEntity::ACTIVITY_IMPORT
            || $logEntity->getActivity() === ImportExportLogEntity::ACTIVITY_DRYRUN
        ) {
            $progress = $importExport->import($context$message->getOffset());
        } elseif ($logEntity->getActivity() === ImportExportLogEntity::ACTIVITY_EXPORT) {
            $progress = $importExport->export($contextnew Criteria()$message->getOffset());
        } else {
            throw new ProcessingException('Unknown activity');
        }

        if (!$progress->isFinished()) {
            $nextMessage = new ImportExportMessage(
                $context,
                $logEntity->getId(),
                $logEntity->getActivity(),
                $progress->getOffset()
            );

            $this->messageBus->dispatch($nextMessage);
        }
    }
}
$expireDate = new \DateTimeImmutable('2099-01-01');
        $file = new UploadedFile(__DIR__ . '/../fixtures/properties.csv', 'properties.csv', 'text/csv');

        $logEntity = $importExportService->prepareImport(
            $context,
            $profileId,
            $expireDate,
            $file
        );

        $importExportMessage = new ImportExportMessage($context$logEntity->getId(), ImportExportLogEntity::ACTIVITY_IMPORT);

        $importExportHandler->__invoke($importExportMessage);

        $messages = $messageBus->getDispatchedMessages();

        $importExportMessage = null;
        foreach ($messages as $message) {
            if (isset($message['message']) && $message['message'] instanceof ImportExportMessage) {
                $importExportMessage = $message['message'];
            }
        }

        
return new JsonResponse(['log' => $log->jsonSerialize()]);
    }

    #[Route(path: '/api/_action/import-export/process', name: 'api.action.import_export.process', methods: ['POST'])]     public function process(Request $request, Context $context): Response
    {
        $logId = strtolower((string) $request->request->get('logId'));

        $importExport = $this->importExportFactory->create($logId, 50, 50);
        $logEntity = $importExport->getLogEntity();

        $message = new ImportExportMessage($context$logEntity->getId()$logEntity->getActivity());

        $this->messageBus->dispatch($message);

        return new Response('', Response::HTTP_NO_CONTENT);
    }

    #[Route(path: '/api/_action/import-export/file/prepare-download/{fileId}', name: 'api.action.import_export.file.prepare-download', methods: ['POST'])]     public function prepareDownload(string $fileId, Context $context): Response
    {
        $token = $this->downloadService->regenerateToken($context$fileId);

        
Home | Imprint | This part of the site doesn't use cookies.