getSourceEntity example

if ($profile instanceof ImportExportProfileEntity) {
            return $profile;
        }

        throw new ProfileNotFoundException($profileId);
    }

    private function checkAllowedReadPrivileges(ImportExportProfileEntity $profile, Context $context): void
    {
        $missingPrivileges = [];

        $sourceEntity = $profile->getSourceEntity();
        $privilege = sprintf('%s:%s', $sourceEntity, AclRoleDefinition::PRIVILEGE_READ);

        if (!$context->isAllowed($privilege)) {
            $missingPrivileges[] = $privilege;
        }

        $definition = $this->definitionInstanceRegistry->getByEntityName($sourceEntity);
        $mappings = $profile->getMapping() ?? [];

        $mappedKeys = array_column($mappings, 'key');
        $propertyPaths = array_map(fn (string $key): array => explode('.', $key)$mappedKeys);

        
$data = $this->prepareImportExportProfileTestData($num);

        $this->repository->create(array_values($data)$this->context);

        foreach ($data as $expect) {
            $id = $expect['id'];
            /** @var ImportExportProfileEntity $importExportProfile */
            $importExportProfile = $this->repository->search(new Criteria([$id])$this->context)->get($id);
            static::assertEquals($expect['name']$importExportProfile->getName());
            static::assertEquals($expect['label']$importExportProfile->getLabel());
            static::assertEquals($expect['systemDefault']$importExportProfile->getSystemDefault());
            static::assertEquals($expect['sourceEntity']$importExportProfile->getSourceEntity());
            static::assertEquals($expect['fileType']$importExportProfile->getFileType());
            static::assertEquals($expect['delimiter']$importExportProfile->getDelimiter());
            static::assertEquals($expect['enclosure']$importExportProfile->getEnclosure());
            static::assertEquals($expect['mapping']$importExportProfile->getMapping());
        }
    }

    public function testImportExportProfileReadNoResult(): void
    {
        $num = 3;
        $data = $this->prepareImportExportProfileTestData($num);

        
public static function getSubscribedEvents(): array
    {
        return [
            EnrichExportCriteriaEvent::class => 'enrich',
        ];
    }

    public function enrich(EnrichExportCriteriaEvent $event): void
    {
        /** @var ImportExportProfileEntity $profile */
        $profile = $event->getLogEntity()->getProfile();
        if ($profile->getSourceEntity() !== CategoryDefinition::ENTITY_NAME) {
            return;
        }

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

        $criteria->addSorting(new FieldSorting('level'));
        $criteria->addSorting(new FieldSorting('id'));
    }
}
foreach ($mappings as $mapping) {
            $headers[$mapping->getMappedKey()] = '';
        }

        // create the file         $expireDate = new \DateTimeImmutable();
        $expireDate = $expireDate->modify('+1 hour');
        $fileEntity = $this->fileService->storeFile(
            $context,
            $expireDate,
            null,
            $profile->getSourceEntity() . ':' . $profile->getName() . '.csv',
            ImportExportLogEntity::ACTIVITY_TEMPLATE
        );

        // write to the file         $targetFile = $fileEntity->getPath();
        $writer = $this->fileService->getWriter();
        $writer->append($config$headers, 0);
        $writer->flush($config$targetFile);
        $writer->finish($config$targetFile);

        return $fileEntity->getId();
    }
public static function getSubscribedEvents(): array
    {
        return [
            EnrichExportCriteriaEvent::class => 'enrich',
        ];
    }

    public function enrich(EnrichExportCriteriaEvent $event): void
    {
        /** @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) {
            
throw new ProcessingException('LogEntity not found');
        }

        return $logEntity;
    }

    private function getRepository(ImportExportLogEntity $logEntity): EntityRepository
    {
        /** @var ImportExportProfileEntity $profile */
        $profile = $logEntity->getProfile();

        return $this->definitionInstanceRegistry->getRepository($profile->getSourceEntity());
    }

    private function getPipe(ImportExportLogEntity $logEntity): AbstractPipe
    {
        foreach ($this->pipeFactories as $factory) {
            if ($factory->supports($logEntity)) {
                return $factory->create($logEntity);
            }
        }

        throw new \RuntimeException('No pipe factory found');
    }
/** * @param Config $config * * @return Config */
    private function getConfig(ImportExportProfileEntity $profileEntity, array $config): array
    {
        $parameters = $profileEntity->getConfig();

        $parameters['delimiter'] = $profileEntity->getDelimiter();
        $parameters['enclosure'] = $profileEntity->getEnclosure();
        $parameters['sourceEntity'] = $profileEntity->getSourceEntity();
        $parameters['fileType'] = $profileEntity->getFileType();
        $parameters['profileName'] = $profileEntity->getName();

        return [
            'mapping' => $config['mapping'] ?? $profileEntity->getMapping(),
            'updateBy' => $config['updateBy'] ?? $profileEntity->getUpdateBy(),
            'parameters' => array_merge($parameters$config['parameters'] ?? []),
        ];
    }
}
Home | Imprint | This part of the site doesn't use cookies.