fromLog example

/** * @return array<array<string, mixed>> */
    protected function getInvalidLogContent(?string $invalidLogId): array
    {
        if (!$invalidLogId) {
            return [];
        }

        $logEntity = $this->getLogEntity($invalidLogId);
        $config = Config::fromLog($logEntity);
        $reader = new CsvReader();
        $filesystem = $this->getContainer()->get('shopware.filesystem.private');

        /** @var ImportExportFileEntity $file */
        $file = $logEntity->getFile();
        $resource = $filesystem->readStream($file->getPath());
        $log = $reader->read($config$resource, 0);

        return $log instanceof \Traversable ? iterator_to_array($log) : [];
    }

    

        $this->profileRepository->create([$profile], Context::createDefaultContext());

        $path = tempnam(sys_get_temp_dir(), '');
        static::assertIsString($path);

        copy(__DIR__ . '/../fixtures/categories.csv', $path);

        $uploadedFile = new UploadedFile($path, 'test', 'text/csv');
        $log = $this->importExportService->prepareImport(Context::createDefaultContext()$profile['id']new \DateTimeImmutable()$uploadedFile);

        $actualConfig = Config::fromLog($log);

        static::assertFalse($actualConfig->get('includeVariants'));
        static::assertSame($profile['delimiter']$actualConfig->get('delimiter'));
        static::assertSame($profile['enclosure']$actualConfig->get('enclosure'));
        static::assertSame($profile['sourceEntity']$actualConfig->get('sourceEntity'));
        static::assertSame($profile['fileType']$actualConfig->get('fileType'));
        static::assertSame($profile['name']$actualConfig->get('profileName'));

        $expectedMapping = MappingCollection::fromIterable($profile['mapping']);
        static::assertEquals($expectedMapping$actualConfig->getMapping());

        


        $processed = 0;

        $path = $file->getPath();
        $progress->setTotal($this->filesystem->fileSize($path));
        $invalidRecordsProgress = null;

        $failedRecords = [];

        $resource = $this->filesystem->readStream($path);
        $config = Config::fromLog($this->logEntity);
        $overallResults = $this->logEntity->getResult();

        $this->eventDispatcher->addListener(WriteCommandExceptionEvent::class$this->onWriteException(...));

        $createEntities = $config->get('createEntities') ?? true;
        $updateEntities = $config->get('updateEntities') ?? true;

        $context->addState(Context::SKIP_TRIGGER_FLOW);

        foreach ($this->reader->read($config$resource$offset) as $row) {
            $event = new ImportExportBeforeImportRowEvent($row$config$context);
            
/** * @dataProvider serializeDataProvider * * @param array<mixed>|Struct|null $entity * @param array<mixed> $expected */
    public function testSerialize($entity, array $expected): void
    {
        $logEntity = new ImportExportLogEntity();
        $logEntity->setId(Uuid::randomHex());
        $config = Config::fromLog($logEntity);
        $definition = new OrderDefinition();
        $definition->compile($this->createMock(DefinitionInstanceRegistry::class));

        $result = iterator_to_array($this->serializer->serialize($config$definition$entity));

        static::assertEquals($expected$result);
    }

    /** * @return iterable<string, array{entity: Struct|array<mixed>|null, expected: array<string, mixed>}> */
    
/** @var ImportExportProfileEntity $profile */
        $profile = $event->getLogEntity()->getProfile();
        if ($profile->getSourceEntity() !== ProductDefinition::ENTITY_NAME) {
            return;
        }

        $criteria = $event->getCriteria();
        $criteria->resetSorting();

        $criteria->addSorting(new FieldSorting('autoIncrement'));

        $config = Config::fromLog($event->getLogEntity());

        if ($config->get('includeVariants') !== true) {
            $criteria->addFilter(new EqualsFilter('parentId', null));
        }
    }
}


        return $result->first();
    }

    private function printErrors(ImportExport $importExport, ImportExportLogEntity $log, SymfonyStyle $io, bool $deleteLog): void
    {
        if (!$importExport->getLogEntity()->getInvalidRecordsLog() || !$log->getFile()) {
            return;
        }

        $config = Config::fromLog($importExport->getLogEntity()->getInvalidRecordsLog());
        $reader = new CsvReader();
        $invalidLogFilePath = $log->getFile()->getPath() . '_invalid';
        $resource = $this->filesystem->readStream($invalidLogFilePath);

        $invalidRows = $reader->read($config$resource, 0);

        foreach ($invalidRows as $invalidRow) {
            $io->note($invalidRow['_error']);
            $io->newLine();
        }

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