Skip to content

Commit

Permalink
Fixed store action lists
Browse files Browse the repository at this point in the history
  • Loading branch information
gauquier committed Dec 4, 2024
1 parent 692574c commit 7010404
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 12 deletions.
11 changes: 5 additions & 6 deletions src/Component/Action/StoreAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,11 @@ public function apply(array $item): array
// start true_action
// make changes list
$changes = $changeManager->getChanges($identifier, $entity.'.values');
$this->configuration->addLists([
'product_changes_fields_added' => $changes['added'],
'product_changes_fields_deleted' => $changes['deleted'],
'product_changes_fields_updated' => $changes['updated'],
'product_changes_fields_all' => $changes['all'],
]);

$this->configuration->updateList('product_changes_fields_added', $changes['added']);
$this->configuration->updateList('product_changes_fields_deleted', $changes['deleted']);
$this->configuration->updateList('product_changes_fields_updated', $changes['updated']);
$this->configuration->updateList('product_changes_fields_all', $changes['all']);

// see GroupAction, get ActionProcessor, process your action(s)
if ([] !== $trueAction) {
Expand Down
12 changes: 12 additions & 0 deletions src/Component/Common/Collection/ArrayCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,16 @@ public function getValues(): array
{
return $this->items;
}

public function addValues(array $items): void
{
foreach (array_filter($items) as $key => $item) {
$this->set($key, $item);
}
}

public function purge(): void
{
$this->items = [];
}
}
42 changes: 37 additions & 5 deletions src/Component/Configurator/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Configuration
private $decoders;
private $reader;
private $writer;
/** @var ArrayCollection[] $lists */
private $lists = [];
private $mappings = [];
private $filters = [];
Expand Down Expand Up @@ -144,7 +145,7 @@ public function setActions(ItemActionProcessor $actionProcessor): void
{
$this->actions = $actionProcessor;
}

public function setActionFactory(ItemActionProcessorFactory $factory): void
{
$this->actionFactory = $factory;
Expand Down Expand Up @@ -194,17 +195,43 @@ public function addBlueprints(ArrayCollection $collection): void

public function addLists(array $lists): void
{
$this->lists = array_merge($this->lists, $lists);
foreach ($lists as $listName => $list) {
$this->addList($listName, $list);
}
}

public function addList(string $listName, array $list): void
{
$this->lists[$listName] = new ArrayCollection($list);
}

public function updateList(string $listName, array $list): void
{
/** @var ArrayCollection $currentList */
$currentList = $this->getListObject($listName);
if ($currentList === null) {
$this->addList($listName, $list);
return;
}

$currentList->purge();
$currentList->addValues($list);
}

public function getLists(): array
{
return $this->lists;
return array_map(function ($list) {
return $list->getValues();
}, $this->lists);
}

public function getList(string $alias)
public function getList(string $alias): ?array
{
return $this->lists[$alias] ?? null;
if (!isset($this->lists[$alias])) {
return null;
}

return $this->lists[$alias]->getValues();
}

public function addFilters(array $filters): void
Expand Down Expand Up @@ -333,4 +360,9 @@ public function clear(): void
$this->decoders = new ArrayCollection();
$this->blueprints = new ArrayCollection();
}

private function getListObject(string $alias): ?ArrayCollection
{
return $this->lists[$alias] ?? null;
}
}
2 changes: 1 addition & 1 deletion src/Component/Configurator/ReadOnlyConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function getLists(): array

public function getList(string $alias)
{
return $this->lists[$alias] ?? null;
return $this->lists[$alias]?->getValues();
}

public function getFilter(string $alias)
Expand Down

0 comments on commit 7010404

Please sign in to comment.