From 2f82ffef9b371dff069e178f3dd1a995b7b4da0d Mon Sep 17 00:00:00 2001 From: Thijs De Paepe Date: Wed, 22 Nov 2023 08:38:33 +0100 Subject: [PATCH] added: configurable Fetcher options --- src/Component/Converter/Akeneo/Csv/Product.php | 6 +++--- src/Component/Item/ItemsFactoryIntoItem.php | 2 +- src/Component/Parser/ItemParserFactory.php | 9 +++++++-- src/Component/Parser/XlsxParser.php | 3 ++- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Component/Converter/Akeneo/Csv/Product.php b/src/Component/Converter/Akeneo/Csv/Product.php index 8c6caf3e..4c795986 100644 --- a/src/Component/Converter/Akeneo/Csv/Product.php +++ b/src/Component/Converter/Akeneo/Csv/Product.php @@ -142,13 +142,13 @@ public function revert(array $item): array if (isset($item['enabled'])) { $output['enabled'] = $item['enabled']; } - if (array_key_exists($item['family'])) { + if (array_key_exists('family', $item)) { $output['family'] = $item['family']; } - if (array_key_exists($item['categories'])) { + if (array_key_exists('categories', $item)) { $output['categories'] = $item['categories']; } - if (array_key_exists($item['parent'])) { + if (array_key_exists('parent', $item)) { $output['parent'] = $item['parent']; } $output = $this->decoder->decode($output); diff --git a/src/Component/Item/ItemsFactoryIntoItem.php b/src/Component/Item/ItemsFactoryIntoItem.php index 9e568958..57e68d7d 100644 --- a/src/Component/Item/ItemsFactoryIntoItem.php +++ b/src/Component/Item/ItemsFactoryIntoItem.php @@ -15,7 +15,7 @@ public static function spreadFromConfig( return []; } - $result = array_fill_keys($configuration['list'], ''); + $result = !empty($configuration['list']) ? array_fill_keys($configuration['list'], '') : []; $spreadConfiguration = $configuration['spread']; $attributesToKeep = []; diff --git a/src/Component/Parser/ItemParserFactory.php b/src/Component/Parser/ItemParserFactory.php index 950f054b..9bc0dfe1 100644 --- a/src/Component/Parser/ItemParserFactory.php +++ b/src/Component/Parser/ItemParserFactory.php @@ -24,14 +24,19 @@ public function createFromConfiguration( 'type must be filled in.' )->notEmpty()->string()->inArray(['xml', 'csv', 'xlsx', 'list', 'feed', 'yaml', 'buffer', 'json']); + $fetchers = [ + 'continuous' => ContinuousBufferFetcher::class, + 'zone' => OldCachedZoneFetcher::class + ]; + $classFetcher = $fetchers[strtolower($configuration['fetcher'] ?? 'zone')]; + if (isset($configuration['join'])) { $joins = $configuration['join']; unset($configuration['join']); $mainParser = $this->createFromConfiguration($configuration, $manager); foreach ($joins as $join) { - $fetcher = clone new OldCachedZoneFetcher($this->createFromConfiguration($join, $manager), $join['link_join'], $join['allow_fileindex_removal'] ?? false); - ##$fetcher = clone new ContinuousBufferFetcher($this->createFromConfiguration($join, $manager), $join['link_join'], $join['allow_fileindex_removal'] ?? false); + $fetcher = clone new $classFetcher($this->createFromConfiguration($join, $manager), $join['link_join'], $join['allow_fileindex_removal'] ?? false); $mainParser = new FunctionalCursor($mainParser, function ($row) use ($fetcher, $join) { $masterID = $row[$join['link']]; $item = $fetcher->get($masterID) ?? []; diff --git a/src/Component/Parser/XlsxParser.php b/src/Component/Parser/XlsxParser.php index bc34c8f9..6429d249 100644 --- a/src/Component/Parser/XlsxParser.php +++ b/src/Component/Parser/XlsxParser.php @@ -39,7 +39,8 @@ private function init(): void public function current(): mixed { - if ($this->cursor === null) { + if (false === $this->cursor->valid()) { + return false; } $current = $this->cursor->current();