Progress example

$this->createMock(EventDispatcherInterface::class),
            $this->getContainer()->get(Connection::class),
            $this->createMock(EntityRepository::class),
            $pipe,
            $reader,
            $writer,
            $this->getContainer()->get(FileService::class),
        );

        $importExportService->method('getProgress')
            ->willReturnCallback(
                static fn () => new Progress($logEntity->getId()$logEntity->getState())
            );

        $logEntity->setState(Progress::STATE_SUCCEEDED);
        $importExport->import(Context::createDefaultContext());
        $importExport->export(Context::createDefaultContext()new Criteria());

        $logEntity->setState(Progress::STATE_ABORTED);
        $importExport->import(Context::createDefaultContext());
        $importExport->export(Context::createDefaultContext()new Criteria());

        $logEntity->setState(Progress::STATE_FAILED);
        
$this->createMock(EventDispatcherInterface::class),
            $this->createMock(Connection::class),
            $this->createMock(EntityRepository::class),
            $pipe,
            $reader,
            $writer,
            $this->createMock(FileService::class),
        );

        $importExportService->method('getProgress')
            ->willReturnCallback(
                static fn () => new Progress($logEntity->getId()$logEntity->getState())
            );

        $logEntity->setState(Progress::STATE_SUCCEEDED);
        $importExport->import(Context::createDefaultContext());

        $logEntity->setState(Progress::STATE_ABORTED);
        $importExport->import(Context::createDefaultContext());

        $logEntity->setState(Progress::STATE_FAILED);
        $importExport->import(Context::createDefaultContext());
    }

    
$total = filesize($filePath);
        if ($total === false) {
            $total = 0;
        }
        $progressBar = $io->createProgressBar($total);

        $io->title(sprintf('Starting import of size %d ', $total));

        $records = 0;

        $progress = new Progress($log->getId(), Progress::STATE_PROGRESS, 0);
        do {
            $progress = $importExport->import(Context::createDefaultContext()$progress->getOffset());
            $progressBar->setProgress($progress->getOffset());
            $records += $progress->getProcessedRecords();
        } while (!$progress->isFinished());

        $elapsed = time() - $startTime;
        $io->newLine(2);

        if ($printErrors) {
            $this->printErrors($importExport$log$io$doRollback && $progress->getState() === Progress::STATE_FAILED);
        }
$config = array_merge($clonedCustomerProfile->getConfig()$configOverrides);
        $this->updateProfileConfig($clonedCustomerProfile->getId()$config);

        $file = new UploadedFile(__DIR__ . '/fixtures/customers.csv', 'customers_used_with_config.csv', 'text/csv');
        $logEntity = $importExportService->prepareImport(
            $context,
            $clonedCustomerProfile->getId(),
            $expireDate,
            $file
        );

        $progress = new Progress($logEntity->getId(), Progress::STATE_PROGRESS, 0, null);

        $pipeFactory = $this->getContainer()->get(PipeFactory::class);
        $readerFactory = $this->getContainer()->get(CsvReaderFactory::class);
        $writerFactory = $this->getContainer()->get(CsvFileWriterFactory::class);

        $mockRepository = new MockRepository($this->getContainer()->get(CustomerDefinition::class));

        $importExport = new ImportExport(
            $importExportService,
            $logEntity,
            $this->getContainer()->get('shopware.filesystem.private'),
            
$adminSource = new AdminApiSource('userId');
        $adminSource->setIsAdmin(true);
        $context = Context::createDefaultContext($adminSource);

        $importExportHandler = new ImportExportHandler($messageBus$factory);

        $logEntity = new ImportExportLogEntity();
        $logEntity->setActivity($activity);
        $logEntity->setState(Progress::STATE_PROGRESS);
        $logEntity->setId('logId');

        $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());

        
return $this->createLog($context$activity$fileEntity$profileEntity$config);
    }

    public function cancel(Context $context, string $logId): void
    {
        $logEntity = $this->findLog($context$logId);

        if ($logEntity === null) {
            throw new ProcessingException('LogEntity not found');
        }

        $canceledProgress = new Progress($logId, Progress::STATE_ABORTED);
        $canceledProgress->addProcessedRecords($logEntity->getRecords());

        $this->saveProgress($canceledProgress);
    }

    public function getProgress(string $logId, int $offset): Progress
    {
        $criteria = new Criteria([$logId]);
        $criteria->addAssociation('file');
        $current = $this->logRepository->search($criteria, Context::createDefaultContext())->first();
        if (!$current instanceof ImportExportLogEntity) {
            
Home | Imprint | This part of the site doesn't use cookies.