Issue #2796393 by Jo Fitzgerald, tacituseu, Stefan Freudenberg, Yogesh Pawar, heddn, mpp, GaëlG: Migration process plugin not working with multiple source IDs

8.5.x
Lee Rowlands 2017-10-12 15:39:14 +10:00
parent 844b6d3bf6
commit f37dea08c2
No known key found for this signature in database
GPG Key ID: 2B829A3DF9204DC4
3 changed files with 67 additions and 7 deletions

View File

@ -161,10 +161,6 @@ class MigrationLookup extends ProcessPluginBase implements ContainerFactoryPlugi
if (!is_array($migration_ids)) {
$migration_ids = [$migration_ids];
}
if (!is_array($value)) {
$value = [$value];
}
$this->skipOnEmpty($value);
$self = FALSE;
/** @var \Drupal\migrate\Plugin\MigrationInterface[] $migrations */
$destination_ids = NULL;
@ -176,13 +172,15 @@ class MigrationLookup extends ProcessPluginBase implements ContainerFactoryPlugi
}
if (isset($this->configuration['source_ids'][$migration_id])) {
$configuration = ['source' => $this->configuration['source_ids'][$migration_id]];
$source_id_values[$migration_id] = $this->processPluginManager
$value = $this->processPluginManager
->createInstance('get', $configuration, $this->migration)
->transform(NULL, $migrate_executable, $row, $destination_property);
}
else {
$source_id_values[$migration_id] = $value;
if (!is_array($value)) {
$value = [$value];
}
$this->skipOnEmpty($value);
$source_id_values[$migration_id] = $value;
// Break out of the loop as soon as a destination ID is found.
if ($destination_ids = $migration->getIdMap()->lookupDestinationId($source_id_values[$migration_id])) {
break;

View File

@ -11,6 +11,7 @@ use Drupal\migrate\Plugin\MigrateIdMapInterface;
use Drupal\migrate\Plugin\MigratePluginManager;
use Drupal\migrate\Plugin\MigrateSourceInterface;
use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
use Drupal\migrate\Row;
use Prophecy\Argument;
/**
@ -100,6 +101,8 @@ class MigrationLookupTest extends MigrateProcessTestCase {
'migration' => 'foobaz',
];
$migration_plugin->id()->willReturn(uniqid());
$migration_plugin_manager->createInstances(['foobaz'])
->willReturn(['foobaz' => $migration_plugin->reveal()]);
$migration = new MigrationLookup($configuration, 'migration_lookup', [], $migration_plugin->reveal(), $migration_plugin_manager->reveal(), $process_plugin_manager->reveal());
$this->setExpectedException(MigrateSkipProcessException::class);
$migration->transform(0, $this->migrateExecutable, $this->row, 'foo');
@ -238,4 +241,61 @@ class MigrationLookupTest extends MigrateProcessTestCase {
$migration->transform(1, $this->migrateExecutable, $this->row, '');
}
/**
* Tests processing multiple source IDs.
*/
public function testMultipleSourceIds() {
$migration_plugin = $this->prophesize(MigrationInterface::class);
$migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class);
$process_plugin_manager = $this->prophesize(MigratePluginManager::class);
$foobaz_migration = $this->prophesize(MigrationInterface::class);
$get_migration = $this->prophesize(MigrationLookup::class);
$id_map = $this->prophesize(MigrateIdMapInterface::class);
$destination_plugin = $this->prophesize(MigrateDestinationInterface::class);
$source_plugin = $this->prophesize(MigrateSourceInterface::class);
$migration_plugin_manager->createInstances(['foobaz'])
->willReturn(['foobaz' => $foobaz_migration->reveal()]);
$process_plugin_manager->createInstance('get', ['source' => ['string_id', 'integer_id']], $migration_plugin->reveal())
->willReturn($get_migration->reveal());
$foobaz_migration->getIdMap()->willReturn($id_map->reveal());
$foobaz_migration->getDestinationPlugin(TRUE)->willReturn($destination_plugin->reveal());
$foobaz_migration->getProcess()->willReturn([]);
$foobaz_migration->getSourcePlugin()->willReturn($source_plugin->reveal());
$foobaz_migration->id()->willReturn('foobaz');
$foobaz_migration->getSourceConfiguration()->willReturn([]);
$get_migration->transform(NULL, $this->migrateExecutable, $this->row, 'foo')
->willReturn(['example_string', 99]);
$source_plugin_ids = [
'string_id' => [
'type' => 'string',
'max_length' => 128,
'is_ascii' => TRUE,
'alias' => 'wpt',
],
'integer_id' => [
'type' => 'integer',
'unsigned' => FALSE,
'alias' => 'wpt',
],
];
$stub_row = new Row(['string_id' => 'example_string', 'integer_id' => 99], $source_plugin_ids, TRUE);
$destination_plugin->import($stub_row)->willReturn([2]);
$source_plugin->getIds()->willReturn($source_plugin_ids);
$configuration = [
'migration' => 'foobaz',
'source_ids' => ['foobaz' => ['string_id', 'integer_id']],
];
$migration = new MigrationLookup($configuration, 'migration', [], $migration_plugin->reveal(), $migration_plugin_manager->reveal(), $process_plugin_manager->reveal());
$result = $migration->transform(NULL, $this->migrateExecutable, $this->row, 'foo');
$this->assertEquals(2, $result);
}
}

View File

@ -124,6 +124,8 @@ class MigrationTest extends MigrateProcessTestCase {
'migration' => 'foobaz',
];
$this->migration_plugin->id()->willReturn(uniqid());
$this->migration_plugin_manager->createInstances(['foobaz'])
->willReturn(['foobaz' => $this->migration_plugin->reveal()]);
$migration = new Migration($configuration, 'migration', [], $this->migration_plugin->reveal(), $this->migration_plugin_manager->reveal(), $this->process_plugin_manager->reveal());
$this->setExpectedException(MigrateSkipProcessException::class);
$migration->transform(0, $this->migrateExecutable, $this->row, 'foo');