Issue #3196583 by Matroskeen, Wim Leers, quietone, larowlan: MigrationLookup plugin overrides source values for multiple migrations
parent
1640eb2359
commit
eaf2958695
|
@ -58,14 +58,32 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
* process:
|
||||
* uid:
|
||||
* plugin: migration_lookup
|
||||
* migration:
|
||||
* - users
|
||||
* - members
|
||||
* source_ids:
|
||||
* users:
|
||||
* - author
|
||||
* members:
|
||||
* - id
|
||||
* migration:
|
||||
* - users
|
||||
* - members
|
||||
* source_ids:
|
||||
* users:
|
||||
* - author
|
||||
* members:
|
||||
* - id
|
||||
* @endcode
|
||||
*
|
||||
* It's not required to describe source identifiers for each migration. If the
|
||||
* source identifier for a migration is not specified, the default source value
|
||||
* will be used. In the example below, the 'author' source property will be used
|
||||
* to do a lookup in the 'users' migration, and the 'uid' property in the
|
||||
* 'members' migration.
|
||||
* @code
|
||||
* process:
|
||||
* uid:
|
||||
* plugin: migration_lookup
|
||||
* source: uid
|
||||
* migration:
|
||||
* - users
|
||||
* - members
|
||||
* source_ids:
|
||||
* users:
|
||||
* - author
|
||||
* @endcode
|
||||
*
|
||||
* If the migration_lookup plugin does not find the source ID in the migration
|
||||
|
@ -178,22 +196,21 @@ class MigrationLookup extends ProcessPluginBase implements ContainerFactoryPlugi
|
|||
$destination_ids = NULL;
|
||||
$source_id_values = [];
|
||||
foreach ($lookup_migration_ids as $lookup_migration_id) {
|
||||
$lookup_value = $value;
|
||||
if ($lookup_migration_id == $this->migration->id()) {
|
||||
$self = TRUE;
|
||||
}
|
||||
if (isset($this->configuration['source_ids'][$lookup_migration_id])) {
|
||||
$value = array_values($row->getMultiple($this->configuration['source_ids'][$lookup_migration_id]));
|
||||
$lookup_value = array_values($row->getMultiple($this->configuration['source_ids'][$lookup_migration_id]));
|
||||
}
|
||||
if (!is_array($value)) {
|
||||
$value = [$value];
|
||||
}
|
||||
$this->skipInvalid($value);
|
||||
$source_id_values[$lookup_migration_id] = $value;
|
||||
$lookup_value = (array) $lookup_value;
|
||||
$this->skipInvalid($lookup_value);
|
||||
$source_id_values[$lookup_migration_id] = $lookup_value;
|
||||
|
||||
// Re-throw any PluginException as a MigrateException so the executable
|
||||
// can shut down the migration.
|
||||
try {
|
||||
$destination_id_array = $this->migrateLookup->lookup($lookup_migration_id, $value);
|
||||
$destination_id_array = $this->migrateLookup->lookup($lookup_migration_id, $lookup_value);
|
||||
}
|
||||
catch (PluginNotFoundException $e) {
|
||||
$destination_id_array = [];
|
||||
|
|
|
@ -251,4 +251,37 @@ class MigrationLookupTest extends MigrationLookupTestCase {
|
|||
$this->assertEquals(2, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests processing multiple migrations and source IDs.
|
||||
*/
|
||||
public function testMultipleMigrations() {
|
||||
$migration_plugin = $this->prophesize(MigrationInterface::class);
|
||||
$this->migrateLookup->lookup('foobaz', [1])->willReturn([[2]]);
|
||||
$this->migrateLookup->lookup('foobaz', [2])->willReturn([]);
|
||||
$this->migrateLookup->lookup('foobar', [1, 2])->willReturn([]);
|
||||
$this->migrateLookup->lookup('foobar', [3, 4])->willReturn([[5]]);
|
||||
$configuration = [
|
||||
'migration' => ['foobar', 'foobaz'],
|
||||
'source_ids' => [
|
||||
'foobar' => ['foo', 'bar'],
|
||||
],
|
||||
];
|
||||
$migration = MigrationLookup::create($this->prepareContainer(), $configuration, '', [], $migration_plugin->reveal());
|
||||
|
||||
$row1 = $this->row;
|
||||
$row2 = clone $this->row;
|
||||
|
||||
$row1->expects($this->any())
|
||||
->method('getMultiple')
|
||||
->willReturn([1, 2]);
|
||||
$result = $migration->transform([1], $this->migrateExecutable, $row1, '');
|
||||
$this->assertEquals(2, $result);
|
||||
|
||||
$row2->expects($this->any())
|
||||
->method('getMultiple')
|
||||
->willReturn([3, 4]);
|
||||
$result = $migration->transform([2], $this->migrateExecutable, $row2, '');
|
||||
$this->assertEquals(5, $result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue