Issue #2796393 by Jo Fitzgerald, tacituseu, Stefan Freudenberg, Yogesh Pawar, heddn, mpp, GaëlG: Migration process plugin not working with multiple source IDs
parent
844b6d3bf6
commit
f37dea08c2
|
@ -161,10 +161,6 @@ class MigrationLookup extends ProcessPluginBase implements ContainerFactoryPlugi
|
||||||
if (!is_array($migration_ids)) {
|
if (!is_array($migration_ids)) {
|
||||||
$migration_ids = [$migration_ids];
|
$migration_ids = [$migration_ids];
|
||||||
}
|
}
|
||||||
if (!is_array($value)) {
|
|
||||||
$value = [$value];
|
|
||||||
}
|
|
||||||
$this->skipOnEmpty($value);
|
|
||||||
$self = FALSE;
|
$self = FALSE;
|
||||||
/** @var \Drupal\migrate\Plugin\MigrationInterface[] $migrations */
|
/** @var \Drupal\migrate\Plugin\MigrationInterface[] $migrations */
|
||||||
$destination_ids = NULL;
|
$destination_ids = NULL;
|
||||||
|
@ -176,13 +172,15 @@ class MigrationLookup extends ProcessPluginBase implements ContainerFactoryPlugi
|
||||||
}
|
}
|
||||||
if (isset($this->configuration['source_ids'][$migration_id])) {
|
if (isset($this->configuration['source_ids'][$migration_id])) {
|
||||||
$configuration = ['source' => $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)
|
->createInstance('get', $configuration, $this->migration)
|
||||||
->transform(NULL, $migrate_executable, $row, $destination_property);
|
->transform(NULL, $migrate_executable, $row, $destination_property);
|
||||||
}
|
}
|
||||||
else {
|
if (!is_array($value)) {
|
||||||
$source_id_values[$migration_id] = $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.
|
// Break out of the loop as soon as a destination ID is found.
|
||||||
if ($destination_ids = $migration->getIdMap()->lookupDestinationId($source_id_values[$migration_id])) {
|
if ($destination_ids = $migration->getIdMap()->lookupDestinationId($source_id_values[$migration_id])) {
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -11,6 +11,7 @@ use Drupal\migrate\Plugin\MigrateIdMapInterface;
|
||||||
use Drupal\migrate\Plugin\MigratePluginManager;
|
use Drupal\migrate\Plugin\MigratePluginManager;
|
||||||
use Drupal\migrate\Plugin\MigrateSourceInterface;
|
use Drupal\migrate\Plugin\MigrateSourceInterface;
|
||||||
use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
|
use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
|
||||||
|
use Drupal\migrate\Row;
|
||||||
use Prophecy\Argument;
|
use Prophecy\Argument;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -100,6 +101,8 @@ class MigrationLookupTest extends MigrateProcessTestCase {
|
||||||
'migration' => 'foobaz',
|
'migration' => 'foobaz',
|
||||||
];
|
];
|
||||||
$migration_plugin->id()->willReturn(uniqid());
|
$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());
|
$migration = new MigrationLookup($configuration, 'migration_lookup', [], $migration_plugin->reveal(), $migration_plugin_manager->reveal(), $process_plugin_manager->reveal());
|
||||||
$this->setExpectedException(MigrateSkipProcessException::class);
|
$this->setExpectedException(MigrateSkipProcessException::class);
|
||||||
$migration->transform(0, $this->migrateExecutable, $this->row, 'foo');
|
$migration->transform(0, $this->migrateExecutable, $this->row, 'foo');
|
||||||
|
@ -238,4 +241,61 @@ class MigrationLookupTest extends MigrateProcessTestCase {
|
||||||
$migration->transform(1, $this->migrateExecutable, $this->row, '');
|
$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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,6 +124,8 @@ class MigrationTest extends MigrateProcessTestCase {
|
||||||
'migration' => 'foobaz',
|
'migration' => 'foobaz',
|
||||||
];
|
];
|
||||||
$this->migration_plugin->id()->willReturn(uniqid());
|
$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());
|
$migration = new Migration($configuration, 'migration', [], $this->migration_plugin->reveal(), $this->migration_plugin_manager->reveal(), $this->process_plugin_manager->reveal());
|
||||||
$this->setExpectedException(MigrateSkipProcessException::class);
|
$this->setExpectedException(MigrateSkipProcessException::class);
|
||||||
$migration->transform(0, $this->migrateExecutable, $this->row, 'foo');
|
$migration->transform(0, $this->migrateExecutable, $this->row, 'foo');
|
||||||
|
|
Loading…
Reference in New Issue