Skip to content

Commit

Permalink
Merge branch 'master' into obelink-xml-v3
Browse files Browse the repository at this point in the history
  • Loading branch information
Thijzer authored Dec 13, 2024
2 parents dcb2eb9 + dad10b7 commit 6b86a52
Show file tree
Hide file tree
Showing 11 changed files with 294 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Component/Action/FormatAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private function doApply($value)
foreach ($this->getOption('functions') as $function) {
switch ($function) {
case 'replace':
if ($this->getOption('search') && $this->getOption('replace')) {
if ($this->getOption('search') && $this->getOption('replace') !== null) {
$value = str_replace($this->getOption('search'), $this->getOption('replace'), $value);
}
break;
Expand Down
11 changes: 5 additions & 6 deletions src/Component/Action/StoreAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,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
2 changes: 1 addition & 1 deletion src/Component/Akeneo/Client/ApiAttributesEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ApiAttributesEndpoint implements ApiEndpointInterface
public const NAME = 'attributes';

private const ALL = 'attributes';
private const ONE = 'attributes/%s';
private const ONE = 'attributes/%code%';

public function getAll(): string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Component/Akeneo/Client/ApiCategoriesEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ApiCategoriesEndpoint implements ApiEndpointInterface
{
public const NAME = 'categories';
private const ALL = 'categories';
private const ONE = 'categories/%s';
private const ONE = 'categories/%code%';

public function getAll(): string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Component/Akeneo/Client/ApiFamiliesEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ApiFamiliesEndpoint implements ApiEndpointInterface
{
public const NAME = 'families';
private const ALL = 'families';
private const ONE = 'families/%s';
private const ONE = 'families/%code%';

public function getAll(): string
{
Expand Down
7 changes: 4 additions & 3 deletions src/Component/Common/Client/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,17 @@ public function getResponse(): ApiResponse
// obtain response
$content = \curl_exec($this->handle);
$status = \curl_getinfo($this->handle, CURLINFO_HTTP_CODE);
if (in_array($status, [200, 204]) && !$content) {
return ApiResponse::create([], $status);
}

// extract body
$headerSize = curl_getinfo($this->handle, CURLINFO_HEADER_SIZE);
$headers = substr($content, 0, $headerSize);
$content = substr($content, $headerSize);
$headers = $this->getResponseHeaders($headers);

if (in_array($status, [200, 204]) && !$content) {
return ApiResponse::create([], $status);
}

$multi = [];
foreach (explode("\n", $content) as $c) {
$multi[] = \json_decode($c, true);
Expand Down
13 changes: 13 additions & 0 deletions src/Component/Common/Collection/ArrayCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,17 @@ public function toArray(): 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 = [];

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

public function setActionFactory(ItemActionProcessorFactory $factory): void
{
$this->actionFactory = $factory;
Expand Down Expand Up @@ -217,17 +218,41 @@ 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;
}

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 @@ -356,4 +381,9 @@ public function clear(): void
$this->decoders = new ArrayCollection();
$this->blueprints = new ArrayCollection();
}

private function getListObject(string $alias): ?ArrayCollection
{
return $this->lists[$alias] ?? null;
}
}
6 changes: 4 additions & 2 deletions src/Component/Configurator/ReadOnlyConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ public function getResourceCollection(string $name):? ResourceCollectionInterfac

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

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

public function getFilter(string $alias)
Expand Down
29 changes: 29 additions & 0 deletions tests/Component/Action/FormatActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,35 @@ public function testApplyEmptyNumberFunction()
$this->assertEquals(['field' => ''], $result);
}

public function testEmptyReplaceFormatFunction()
{
$item = ['field' => 'A|,B|,C|,D'];

$action = new FormatAction();
$action->setOptions([
'field' => 'field',
'functions' => ['replace'],
'search' => '|,',
'replace' => '',
]);

$result = $action->apply($item);

$this->assertEquals(['field' => 'ABCD'], $result);

$action = new FormatAction();
$action->setOptions([
'field' => 'field',
'functions' => ['replace'],
'search' => '',
'replace' => null,
]);

$result = $action->apply($item);

$this->assertEquals(['field' => 'A|,B|,C|,D'], $result);
}

public function testApplyPrefixFunction()
{
$item = ['field' => '12345'];
Expand Down
Loading

0 comments on commit 6b86a52

Please sign in to comment.