Skip to content

Commit

Permalink
fix: multi-step context issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Thijzer committed Dec 2, 2024
1 parent 27947d8 commit 05e411e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
3 changes: 1 addition & 2 deletions src/Component/Akeneo/Client/HttpReaderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ public function createFromConfiguration(array $configuration, Configuration $con
$resource = $resources->getResource($endpoint);

$queryString = $context['limiters']['querystring'] ?? null;
dd($context);
if ($queryString) {
if (!empty($queryString)) {
$cursor = $resource->querystring($queryString);

return new ApiReader($resource, $cursor);
Expand Down
2 changes: 1 addition & 1 deletion src/Component/Common/Utils/ContextFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static function format(array $context, array $data): array
}

$newData = [];
foreach ($data as $key => &$value) {
foreach ($data as $key => $value) {
if (is_string($key)) {
$newKey = strtr($key, $replacements);
$newData[$newKey] = $value;
Expand Down
7 changes: 6 additions & 1 deletion src/Component/Configurator/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,16 @@ public function setAsMultiStep(): void
$this->isMultiStep = true;
}

public function addContext(array $context)
public function addContext(array $context): void
{
$this->context = array_merge($this->context, $context);
}

public function setContext(string $key, $value): void
{
$this->context[$key] = $value;
}

public function getContext(string $key = null)
{
return $key !== null ? $this->context[$key] ?? null: $this->context;
Expand Down
4 changes: 2 additions & 2 deletions src/Component/Configurator/ConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function init(
);
}

public function setChangeManager(ChangeManager $changeManager)
public function setChangeManager(ChangeManager $changeManager): void
{
$this->config->changeManager = $changeManager;
}
Expand Down Expand Up @@ -108,7 +108,7 @@ public function parseDirectivesFromConfiguration(array $configuration): Configur
case $key === 'transformation_steps';
$this->config->setAsMultiStep();
$this->config->getLogger()->info(sprintf("Multi Step [%s]", basename($this->config->getContext('transformation_file'))));
$this->manager->addTransformationSteps($configuration['transformation_steps'], $configuration);
$this->manager->addTransformationSteps($configuration['transformation_steps'], $configuration, $this->config->getContext());
break;
case $key === 'pipeline';
$this->manager->configurePipelines($configuration['pipeline']);
Expand Down
23 changes: 9 additions & 14 deletions src/Component/Configurator/ConfigurationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,14 @@ public function addContext(array $configuration): void
$this->config->addContext($configuration);
}

public function addTransformationSteps(array $transformationSteps, array $masterConfiguration): void
/**
* TODO this needs to be broken into more steps, not clear
* context grows, but needs to be reset to previous state per step
*/
public function addTransformationSteps(array $transformationSteps, array $masterConfiguration, array $context): void
{
/** @var ProjectDirectories $projectDirectories */
$projectDirectories = $this->factory->getFactory('project_directories');
$debug = $this->config->getContext('debug');
$dirName = pathinfo($this->config->getContext('transformation_file'))['dirname'] ?? null;

unset($masterConfiguration['transformation_steps']);
Expand All @@ -155,13 +158,10 @@ public function addTransformationSteps(array $transformationSteps, array $master
foreach ($withArray as $key => $values) {
if (isset($values[$i])) {
$context[$key] = $values[$i];

// Save the context in the master configuration
$masterConfiguration['context'][$key] = $values[$i];
}
}

$this->addTransformationSteps([$file], $masterConfiguration);
$this->addTransformationSteps([$file], $masterConfiguration, $context);
}
continue;
}
Expand All @@ -177,13 +177,8 @@ public function addTransformationSteps(array $transformationSteps, array $master
$transformationFile = ArrayFunctions::array_filter_recursive(Yaml::parseFile($file), function ($value) {
return $value !== NULL;
});
$configuration = array_replace_recursive($masterConfiguration, $transformationFile, [
'context' => [
'try' => $transformationFile['context']['try'] ?? null,
'debug' => $debug,
'dirname' => $dirName,
'transformation_file' => $file,
]]);
$configuration = array_replace_recursive($transformationFile, $masterConfiguration);
$configuration['context'] = array_merge($configuration['context'], $context);
$configuration = $this->factory->parseDirectivesFromConfiguration($configuration);

// only start the process if our transformation file has a pipeline
Expand All @@ -201,7 +196,7 @@ public function addTransformationSteps(array $transformationSteps, array $master
}
}

public function configureShellCommands(array $configuration)
public function configureShellCommands(array $configuration): void
{
/** @var ShellCommandFactory $factory */
$factory = $this->factory->getFactory('shell');
Expand Down

0 comments on commit 05e411e

Please sign in to comment.