prepareExport example

$newPath = $file->getPath() . '_invalid';

            $config = $this->logEntity->getConfig();
            $config['mapping'][] = [
                'key' => '_error',
                'mappedKey' => '_error',
            ];
            $config = new Config($config['mapping']$config['parameters'] ?? []$config['updateBy'] ?? []);

            if ($this->logEntity->getProfileId() !== null) {
                $failedImportLogEntity = $this->importExportService->prepareExport(
                    $context,
                    $this->logEntity->getProfileId(),
                    $file->getExpireDate(),
                    $newName,
                    $config->jsonSerialize(),
                    $newPath,
                    ImportExportLogEntity::ACTIVITY_INVALID_RECORDS_EXPORT
                );

                $this->logEntity->setInvalidRecordsLog($failedImportLogEntity);
                $this->logEntity->setInvalidRecordsLogId($failedImportLogEntity->getId());
            }
$this->Front()->setParam('disableOutputBuffering', true);
        $this->export = Shopware()->Modules()->Export();
    }

    /** * Index action method * * Creates the export product. */
    public function indexAction()
    {
        $this->prepareExport();
        $this->sendHeaders();

        $productFeed = $this->get('models')->getRepository('\Shopware\Models\ProductFeed\ProductFeed')->find((int) $this->Request()->feedID);

        // Live generation         if ($productFeed->getInterval() === 0) {
            $this->generateExport('php://output');

            return;
        }

        
$profile->getId(),
                $expireDate,
                $file,
                $request->request->all('config'),
                $request->request->has('dryRun')
            );

            unlink($file->getPathname());
        } else {
            $this->checkAllowedReadPrivileges($profile$context);

            $log = $this->importExportService->prepareExport(
                $context,
                $profile->getId(),
                $expireDate,
                null,
                $request->request->all('config')
            );
        }

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

    
$path = tempnam(sys_get_temp_dir(), '');
        static::assertIsString($path);
        $uploadedFile = new UploadedFile($path, 'test', 'text/csv');

        if ($shouldThrowException) {
            static::expectException(ProfileWrongTypeException::class);
        }

        if ($task === 'import') {
            $this->importExportService->prepareImport(Context::createDefaultContext()$profile['id']new \DateTimeImmutable()$uploadedFile);
        } else {
            $this->importExportService->prepareExport(Context::createDefaultContext()$profile['id']new \DateTimeImmutable());
        }
    }

    public static function profileProvider(): array
    {
        return [
            [
                [
                    'id' => Uuid::randomHex(),
                    'name' => 'Test Profile',
                    'label' => 'Test Profile',
                    


    protected function export(Context $context, string $entityName, ?Criteria $criteria = null, ?int $groupSize = null, ?string $profileId = null): Progress
    {
        $factory = $this->getContainer()->get(ImportExportFactory::class);

        $importExportService = $this->getContainer()->get(ImportExportService::class);

        $profileId ??= $this->getDefaultProfileId($entityName);

        $expireDate = new \DateTimeImmutable('2099-01-01');
        $logEntity = $importExportService->prepareExport($context$profileId$expireDate);

        $progress = new Progress($logEntity->getId(), Progress::STATE_PROGRESS, 0, null);
        do {
            $groupSize = $groupSize ? $groupSize - 1 : 0;
            $criteria ??= new Criteria();
            $importExport = $factory->create($logEntity->getId()$groupSize$groupSize);
            $progress = $importExport->export(Context::createDefaultContext()$criteria$progress->getOffset());
        } while (!$progress->isFinished());

        return $progress;
    }

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