Skip to content

Import PoC#12

Merged
mpysiak merged 5 commits intoSylius:mainfrom
mpysiak:import-poc
Jul 15, 2025
Merged

Import PoC#12
mpysiak merged 5 commits intoSylius:mainfrom
mpysiak:import-poc

Conversation

@mpysiak
Copy link
Member

@mpysiak mpysiak commented Jul 10, 2025

No description provided.

@mpysiak mpysiak force-pushed the import-poc branch 3 times, most recently from fffe075 to e9de8a2 Compare July 14, 2025 05:05
@mpysiak mpysiak force-pushed the import-poc branch 3 times, most recently from 3b2f2e9 to 12c24d0 Compare July 15, 2025 05:29
@mpysiak mpysiak marked this pull request as ready for review July 15, 2025 07:45

public function __invoke(Request $request, string $grid): Response
{
$request->attributes->set('_sylius', array_merge($request->attributes->get('_sylius', []), ['grid' => $grid]));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems unneeded in this case

} catch (\Throwable $e) {
/** @var Session $session */
$session = $request->getSession();
$session->getFlashBag()->add('error', 'sylius_import_export.import_failed: ' . $e->getMessage());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this concat work?

Comment on lines +68 to +70
$this->entityManager->getClassMetadata($type);

return isset($data['id']) || isset($data['code']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure we should read unique fields from the metadata and check if either of them is set. In case of customers we would base on the email for instance.

Comment on lines +52 to +55
private function processFormConfig(ContainerBuilder $container): void
{
$container->setParameter('sylius_import_export.export_files_directory', '%kernel.project_dir%/var/export');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this a form config?

Comment on lines +52 to +53
// Add import action only to main group for now
$this->addInActionGroup($grid, ActionGroupInterface::MAIN_GROUP);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure we won't have either a bulk or an item as they make no sense

throw new \InvalidArgumentException();
}

return json_decode($content, true, 512, \JSON_THROW_ON_ERROR);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably change all of these to symfony decoders further down the line

Comment on lines +41 to +52
$importedCount = 0;
$resourceClass = $process->getResource();
$denormalizer = $this->denormalizerRegistry->get($resourceClass);

foreach ($command->batchData as $recordData) {
$entity = $denormalizer->denormalize($recordData, $resourceClass);
$this->entityManager->persist($entity);

++$importedCount;
}

$this->entityManager->flush();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this should be wrapped in a transaction, so we'd save all or nothing per batch, reverting should also be easier in that case

public function resolve(string $format): ImporterInterface
{
if (!$this->importers->has($format)) {
throw new InvalidArgumentException(sprintf('Importer for "%s" format was not found.', $format));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new InvalidArgumentException(sprintf('Importer for "%s" format was not found.', $format));
throw new \InvalidArgumentException(sprintf('Importer for "%s" format was not found.', $format));

@mpysiak mpysiak merged commit 2845bc0 into Sylius:main Jul 15, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants