Skip to content

Commit

Permalink
ref support, fix seeking, improved templates
Browse files Browse the repository at this point in the history
  • Loading branch information
Thijzer committed Dec 2, 2024
1 parent dc23d47 commit 10d3586
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
context:
filter: []
identifier_filter_list: []
query: ''

pipeline:
input:
http:
type: rest_api
account: '%akeneo_read_connection%'
endpoint: '%endpoint%'
method: GET
filter: '%filter%'
identifier_filter_list: '%identifier_filter_list%'
limiters:
querystring: '%query%'
output:
writer:
type: jsonl
Expand Down
10 changes: 7 additions & 3 deletions src/Component/Action/StoreAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class StoreAction implements ActionInterface, OptionsInterface, ConfigurationAwa
public ItemActionProcessor $trueActionProcessor;
public ItemActionProcessor $falseActionProcessor;

/** @var array */
private $defaults = [
private array $defaults = [
'change_manager' => [
'all_values' => true,
'values' => [],
Expand All @@ -48,6 +47,7 @@ class StoreAction implements ActionInterface, OptionsInterface, ConfigurationAwa
'scope' => null,
],
],
'store_product' => true,
'init' => false,
'true_action' => [],
'false_action' => [],
Expand Down Expand Up @@ -147,6 +147,10 @@ public function apply(array $item): array

private function storeProduct(string $identifier): void
{
$this->configuration->changeManager->persistChange($identifier);
$storeProduct = $this->getOption('store_product');

if ($storeProduct) {
$this->configuration->changeManager->persistChange($identifier);
}
}
}
14 changes: 12 additions & 2 deletions src/Component/Akeneo/Client/HttpReaderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use App\Component\Akeneo\Api\Resources\AkeneoCategoryResource;
use App\Component\Akeneo\Api\Resources\AkeneoFamiliesResource;
use App\Component\Akeneo\Api\Resources\AkeneoProductsResource;
use App\Component\Akeneo\Api\Resources\AkeneoReferenceEntityRecordResource;
use App\Component\Akeneo\Api\Resources\AkeneoReferenceEntityResource;
use App\Component\Common\Cursor\MultiCursor;
use App\Component\Common\Resource\EntityResourceInterface;
use App\Component\Common\Resource\SearchAbleEntityResourceInterface;
Expand Down Expand Up @@ -86,6 +88,7 @@ public function createFromConfiguration(array $configuration, Configuration $con
'categories' => AkeneoCategoryResource::NAME,
'products' => AkeneoProductsResource::NAME,
'options' => AkeneoAttributeOptionsResource::NAME,
'reference-entities' => AkeneoReferenceEntityRecordResource::NAME,
];
$endpoint = $endpoints[$endpoint] ?? null;

Expand All @@ -99,7 +102,6 @@ public function createFromConfiguration(array $configuration, Configuration $con

return new ApiReader($resource, $cursor);
}
dd($configuration);

$queryString = $context['limiters']['querystring'] ?? null;
if (!empty($queryString)) {
Expand All @@ -108,7 +110,15 @@ public function createFromConfiguration(array $configuration, Configuration $con
return new ApiReader($resource, $cursor);
}

if (!empty($configuration['identifier_filter_list'])) {
if (!empty($configuration['identifier_filter_list']) && $endpoint === AkeneoReferenceEntityRecordResource::NAME) {
$cursor = new MultiCursor();
foreach ($configuration['identifier_filter_list'] as $identifier) {
$cursor->addCursor($resource->getAllRecords($identifier));
}
return new ApiReader($resource, $cursor);
}

if (!empty($configuration['identifier_filter_list']) && $endpoint === 'akeneo_attributes') {
$cursor = new MultiCursor();
foreach ($configuration['identifier_filter_list'] as $identifier) {
$cursor->addCursor($resource->getAllByAttributeCode($identifier));
Expand Down
2 changes: 1 addition & 1 deletion src/Component/Converter/AkeneoProductApiConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function convert(array $item): array
// first we need to convert the values
foreach ($item[$container] ?? [] as $key => $valueSet) {
foreach ($valueSet ?? [] as $value) {
$matcher = Matcher::create($container.'|'.$key, $value['locale'], $value['scope']);
$matcher = Matcher::create($container.'|'.$key, $value['locale'] ?? null, $value['scope'] ?? null);
$tmp[$keyMain = $matcher->getMainKey()] = $value['data'] ?? null;
if ($this->getOption('structure') === 'matcher') {
$tmp[$keyMain] = $value;
Expand Down
2 changes: 1 addition & 1 deletion src/Component/Reader/ItemReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function index(array $lines): ItemReaderInterface
private function processIndex(array $lines): \Generator
{
foreach ($lines as $lineNr) {
$this->seek($lineNr);
$this->cursor instanceof \SeekableIterator ? $this->cursor->seek($lineNr) : $this->seek($lineNr);
yield $lineNr => $this->cursor->current();
}
}
Expand Down

0 comments on commit 10d3586

Please sign in to comment.