Skip to content

Commit

Permalink
Fix: when a sub-migration is skipped in a step of a loop, do not halt…
Browse files Browse the repository at this point in the history
… the loop immediately but go on un til the end; references are now resolved for the "over" element of loops
  • Loading branch information
gggeek committed Nov 8, 2018
1 parent 65e33af commit 5980e71
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Core/Executor/IgnorableStepExecutorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ protected function matchConditions($conditions)
return reset($match);
}

}
}
24 changes: 18 additions & 6 deletions Core/Executor/LoopExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Kaliop\eZMigrationBundle\API\Value\MigrationStep;
use Kaliop\eZMigrationBundle\Core\MigrationService;
use Kaliop\eZMigrationBundle\Core\ReferenceResolver\LoopResolver;
use Kaliop\eZMigrationBundle\API\ReferenceResolverInterface;
use Kaliop\eZMigrationBundle\API\Exception\MigrationStepSkippedException;

class LoopExecutor extends AbstractExecutor
{
Expand All @@ -18,10 +20,13 @@ class LoopExecutor extends AbstractExecutor
/** @var LoopResolver $loopResolver */
protected $loopResolver;

public function __construct($migrationService, $loopResolver)
protected $referenceResolver;

public function __construct($migrationService, $loopResolver, ReferenceResolverInterface $referenceResolver)
{
$this->migrationService = $migrationService;
$this->loopResolver = $loopResolver;
$this->referenceResolver = $referenceResolver;
}

/**
Expand Down Expand Up @@ -64,17 +69,20 @@ public function execute(MigrationStep $step)

$this->loopResolver->beginLoop();
$result = null;

if (isset($step->dsl['over'])) {
foreach ($step->dsl['over'] as $key => $value) {

$over = $this->referenceResolver->resolveReference($step->dsl['over']);
foreach ($over as $key => $value) {
$this->loopResolver->loopStep($key, $value);

foreach ($step->dsl['steps'] as $j => $stepDef) {
$type = $stepDef['type'];
unset($stepDef['type']);
$subStep = new MigrationStep($type, $stepDef, array_merge($step->context, array()));
$result = $stepExecutors[$j]->execute($subStep);
try {
$result = $stepExecutors[$j]->execute($subStep);
} catch(MigrationStepSkippedException $e) {
// all ok, continue the loop
}
}
}
} else {
Expand All @@ -87,7 +95,11 @@ public function execute(MigrationStep $step)
$type = $stepDef['type'];
unset($stepDef['type']);
$subStep = new MigrationStep($type, $stepDef, array_merge($step->context, array()));
$result = $stepExecutors[$j]->execute($subStep);
try {
$result = $stepExecutors[$j]->execute($subStep);
} catch(MigrationStepSkippedException $e) {
// all ok, continue the loop
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ services:
arguments:
- '@ez_migration_bundle.migration_service'
- '@ez_migration_bundle.reference_resolver.loop'
- '@ez_migration_bundle.reference_resolver.customreference'
calls:
- ['setReferenceMatcher', ['@ez_migration_bundle.reference_matcher']]
tags:
Expand Down
8 changes: 8 additions & 0 deletions WHATSNEW.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Version 5.4.1
=============

* Fix: when a sub-migration is skipped in a step of a loop, do not halt the loop immediately but go on un til the end

* Fix: references are now resolved for the "over" element of loops


Version 5.4
===========

Expand Down

0 comments on commit 5980e71

Please sign in to comment.