Conversation
fffe075 to
e9de8a2
Compare
3b2f2e9 to
12c24d0
Compare
|
|
||
| public function __invoke(Request $request, string $grid): Response | ||
| { | ||
| $request->attributes->set('_sylius', array_merge($request->attributes->get('_sylius', []), ['grid' => $grid])); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
Does this concat work?
| $this->entityManager->getClassMetadata($type); | ||
|
|
||
| return isset($data['id']) || isset($data['code']); |
There was a problem hiding this comment.
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.
| private function processFormConfig(ContainerBuilder $container): void | ||
| { | ||
| $container->setParameter('sylius_import_export.export_files_directory', '%kernel.project_dir%/var/export'); | ||
| } |
There was a problem hiding this comment.
How is this a form config?
| // Add import action only to main group for now | ||
| $this->addInActionGroup($grid, ActionGroupInterface::MAIN_GROUP); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
We could probably change all of these to symfony decoders further down the line
| $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(); |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
| throw new InvalidArgumentException(sprintf('Importer for "%s" format was not found.', $format)); | |
| throw new \InvalidArgumentException(sprintf('Importer for "%s" format was not found.', $format)); |
No description provided.