Commit 5a27c272 authored by catch's avatar catch

Issue #3068089 by alexpott, mikelutz: Properly deprecate...

Issue #3068089 by alexpott, mikelutz: Properly deprecate \Drupal\migrate\Plugin\MigrateIdMapInterface::lookupDestinationId()
parent 012b0c73
......@@ -197,7 +197,7 @@ public function testEntityDisplaySettings() {
$component = $display->getComponent('field_test_datetime');
$this->assertIdentical($expected, $component);
// Test that our Id map has the correct data.
$this->assertIdentical(['node', 'story', 'teaser', 'field_test'], $this->getMigration('d6_field_formatter_settings')->getIdMap()->lookupDestinationId(['story', 'teaser', 'node', 'field_test']));
$this->assertIdentical([['node', 'story', 'teaser', 'field_test']], $this->getMigration('d6_field_formatter_settings')->getIdMap()->lookupDestinationIds(['story', 'teaser', 'node', 'field_test']));
// Test hidden field.
$this->assertComponentNotExists('node.test_planet.teaser', 'field_test_text_single_checkbox');
......
......@@ -44,7 +44,7 @@ public function testUploadEntityDisplay() {
$component = $display->getComponent('upload');
$this->assertTrue(is_null($component));
$this->assertIdentical(['node', 'page', 'default', 'upload'], $this->getMigration('d6_upload_entity_display')->getIdMap()->lookupDestinationId(['page']));
$this->assertIdentical([['node', 'page', 'default', 'upload']], $this->getMigration('d6_upload_entity_display')->getIdMap()->lookupDestinationIds(['page']));
}
/**
......
......@@ -44,7 +44,7 @@ public function testUploadEntityFormDisplay() {
$component = $display->getComponent('upload');
$this->assertTrue(is_null($component));
$this->assertIdentical(['node', 'page', 'default', 'upload'], $this->getMigration('d6_upload_entity_form_display')->getIdMap()->lookupDestinationId(['page']));
$this->assertIdentical([['node', 'page', 'default', 'upload']], $this->getMigration('d6_upload_entity_form_display')->getIdMap()->lookupDestinationIds(['page']));
}
/**
......
......@@ -31,7 +31,7 @@ protected function setUp() {
public function testUpload() {
$field_storage = FieldStorageConfig::load('node.upload');
$this->assertIdentical('node.upload', $field_storage->id());
$this->assertIdentical(['node', 'upload'], $this->getMigration('d6_upload_field')->getIdMap()->lookupDestinationId(['']));
$this->assertIdentical([['node', 'upload']], $this->getMigration('d6_upload_field')->getIdMap()->lookupDestinationIds(['']));
}
}
......@@ -43,7 +43,7 @@ public function testUploadFieldInstance() {
$field = FieldConfig::load('node.article.upload');
$this->assertTrue(is_null($field));
$this->assertIdentical(['node', 'page', 'upload'], $this->getMigration('d6_upload_field_instance')->getIdMap()->lookupDestinationId(['page']));
$this->assertIdentical([['node', 'page', 'upload']], $this->getMigration('d6_upload_field_instance')->getIdMap()->lookupDestinationIds(['page']));
}
}
......@@ -56,6 +56,7 @@ public function lookupSourceId(array $destination_id_values) {
* {@inheritdoc}
*/
public function lookupDestinationId(array $source_id_values) {
@trigger_error(__NAMESPACE__ . '\NullIdMap::lookupDestinationId() is deprecated in drupal:8.1.0 and is removed from drupal:9.0.0. Use Sql::lookupDestinationIds() instead. See https://www.drupal.org/node/2725809', E_USER_DEPRECATED);
return [];
}
......
......@@ -545,6 +545,7 @@ public function lookupSourceId(array $destination_id_values) {
* {@inheritdoc}
*/
public function lookupDestinationId(array $source_id_values) {
@trigger_error(__NAMESPACE__ . '\Sql::lookupDestinationId() is deprecated in drupal:8.1.0 and is removed from drupal:9.0.0. Use Sql::lookupDestinationIds() instead. See https://www.drupal.org/node/2725809', E_USER_DEPRECATED);
$results = $this->lookupDestinationIds($source_id_values);
return $results ? reset($results) : [];
}
......
......@@ -182,7 +182,9 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
$this->skipInvalid($value);
$source_id_values[$lookup_migration_id] = $value;
// Break out of the loop as soon as a destination ID is found.
if ($destination_ids = $lookup_migration->getIdMap()->lookupDestinationId($source_id_values[$lookup_migration_id])) {
$lookup = $lookup_migration->getIdMap()->lookupDestinationIds($source_id_values[$lookup_migration_id]);
if (!empty($lookup)) {
$destination_ids = $lookup[0];
break;
}
}
......
......@@ -423,11 +423,11 @@ public function testLookupDestinationIdMapping($num_source_fields, $num_destinat
$this->saveMap($row);
$id_map = $this->getIdMap();
// Test for a valid hit.
$destination_id = $id_map->lookupDestinationId($source_id_values);
$this->assertSame($expected_result, $destination_id);
$destination_ids = $id_map->lookupDestinationIds($source_id_values);
$this->assertSame([$expected_result], $destination_ids);
// Test for a miss.
$destination_id = $id_map->lookupDestinationId($nonexistent_id_values);
$this->assertSame(0, count($destination_id));
$destination_ids = $id_map->lookupDestinationIds($nonexistent_id_values);
$this->assertSame(0, count($destination_ids));
}
/**
......@@ -549,6 +549,31 @@ public function testLookupDestinationIds() {
$this->assertNotEquals([[101, 'en']], $id_map->lookupDestinationIds([1, 'en']));
}
/**
* Tests lookupDestinationId().
*
* @group legacy
* @expectedDeprecation Drupal\migrate\Plugin\migrate\id_map\Sql::lookupDestinationId() is deprecated in drupal:8.1.0 and is removed from drupal:9.0.0. Use Sql::lookupDestinationIds() instead. See https://www.drupal.org/node/2725809
*/
public function testLookupDestinationId() {
// Simple map with one source and one destination ID.
$id_map = $this->setupRows(['nid'], ['nid'], [
[1, 101],
[2, 102],
[3, 103],
]);
// Lookup nothing, gives nothing.
$this->assertEquals([], $id_map->lookupDestinationId([]));
// Lookup by complete non-associative list.
$this->assertEquals([101], $id_map->lookupDestinationId([1]));
$this->assertEquals([], $id_map->lookupDestinationId([99]));
// Lookup by complete associative list.
$this->assertEquals([101], $id_map->lookupDestinationId(['nid' => 1]));
}
/**
* Tests the getRowByDestination method.
*/
......
......@@ -29,7 +29,7 @@ public function testTransformWithStubSkipping() {
$destination_id_map = $this->prophesize(MigrateIdMapInterface::class);
$destination_migration = $this->prophesize(MigrationInterface::class);
$destination_migration->getIdMap()->willReturn($destination_id_map->reveal());
$destination_id_map->lookupDestinationId([1])->willReturn(NULL);
$destination_id_map->lookupDestinationIds([1])->willReturn(NULL);
// Ensure the migration plugin manager returns our migration.
$migration_plugin_manager->createInstances(Argument::exact(['destination_migration']))
......@@ -60,7 +60,7 @@ public function testTransformWithStubbing() {
$destination_migration->getIdMap()->willReturn($destination_id_map->reveal());
$migration_plugin_manager->createInstances(['destination_migration'])
->willReturn(['destination_migration' => $destination_migration->reveal()]);
$destination_id_map->lookupDestinationId([1])->willReturn(NULL);
$destination_id_map->lookupDestinationIds([1])->willReturn(NULL);
$destination_id_map->saveIdMapping(Argument::any(), Argument::any(), MigrateIdMapInterface::STATUS_NEEDS_UPDATE)->willReturn(NULL);
$configuration = [
......@@ -137,7 +137,7 @@ public function testNoSkipValid($value) {
$migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class);
$process_plugin_manager = $this->prophesize(MigratePluginManager::class);
$id_map = $this->prophesize(MigrateIdMapInterface::class);
$id_map->lookupDestinationId([$value])->willReturn([]);
$id_map->lookupDestinationIds([$value])->willReturn([]);
$migration_plugin->getIdMap()->willReturn($id_map->reveal());
$configuration = [
......@@ -192,7 +192,7 @@ public function testSuccessfulLookup($source_id_values, $destination_id_values,
$migration_plugin->id()->willReturn(uniqid());
$id_map = $this->prophesize(MigrateIdMapInterface::class);
$id_map->lookupDestinationId($source_id_values)->willReturn($destination_id_values);
$id_map->lookupDestinationIds($source_id_values)->willReturn([$destination_id_values]);
$migration_plugin->getIdMap()->willReturn($id_map->reveal());
$migration_plugin_manager->createInstances(['foobaz'])
......@@ -284,7 +284,7 @@ public function testImportException() {
$destination_migration->getIdMap()->willReturn($destination_id_map->reveal());
$migration_plugin_manager->createInstances(['destination_migration'])
->willReturn(['destination_migration' => $destination_migration->reveal()]);
$destination_id_map->lookupDestinationId([1])->willReturn(NULL);
$destination_id_map->lookupDestinationIds([1])->willReturn(NULL);
$destination_id_map->saveMessage(Argument::any(), Argument::any())->willReturn(NULL);
$destination_id_map->saveIdMapping(Argument::any(), Argument::any(), Argument::any())->shouldNotBeCalled();
......
......@@ -108,7 +108,7 @@ public function testTransformWithStubbing() {
*/
protected function getMigration() {
$id_map = $this->prophesize(MigrateIdMapInterface::class);
$id_map->lookupDestinationId([1])->willReturn(NULL);
$id_map->lookupDestinationIds([1])->willReturn(NULL);
$id_map->saveIdMapping(Argument::any(), Argument::any(), MigrateIdMapInterface::STATUS_NEEDS_UPDATE)->willReturn(NULL);
$migration = $this->prophesize(MigrationInterface::class);
......@@ -152,7 +152,7 @@ public function testSuccessfulLookup($source_id_values, $destination_id_values,
$this->migration_plugin->id()->willReturn(uniqid());
$id_map = $this->prophesize(MigrateIdMapInterface::class);
$id_map->lookupDestinationId($source_id_values)->willReturn($destination_id_values);
$id_map->lookupDestinationIds($source_id_values)->willReturn([$destination_id_values]);
$this->migration_plugin->getIdMap()->willReturn($id_map->reveal());
$this->migration_plugin_manager->createInstances(['foobaz'])
......
......@@ -38,7 +38,7 @@ public function testNodeType() {
$this->assertIdentical(TRUE, $node_type_page->displaySubmitted());
$this->assertIdentical(FALSE, $node_type_page->isNewRevision());
$this->assertIdentical(DRUPAL_OPTIONAL, $node_type_page->getPreviewMode());
$this->assertIdentical($id_map->lookupDestinationId(['test_page']), ['test_page']);
$this->assertIdentical($id_map->lookupDestinationIds(['test_page']), [['test_page']]);
// Test we have a body field.
$field = FieldConfig::loadByName('node', 'test_page', 'body');
......@@ -57,7 +57,7 @@ public function testNodeType() {
$this->assertIdentical(TRUE, $node_type_story->displaySubmitted());
$this->assertIdentical(FALSE, $node_type_story->isNewRevision());
$this->assertIdentical(DRUPAL_OPTIONAL, $node_type_story->getPreviewMode());
$this->assertIdentical($id_map->lookupDestinationId(['test_story']), ['test_story']);
$this->assertIdentical($id_map->lookupDestinationIds(['test_story']), [['test_story']]);
// Test we don't have a body field.
$field = FieldConfig::loadByName('node', 'test_story', 'body');
......@@ -76,7 +76,7 @@ public function testNodeType() {
$this->assertIdentical(TRUE, $node_type_event->displaySubmitted());
$this->assertIdentical(TRUE, $node_type_event->isNewRevision());
$this->assertIdentical(DRUPAL_OPTIONAL, $node_type_event->getPreviewMode());
$this->assertIdentical($id_map->lookupDestinationId(['test_event']), ['test_event']);
$this->assertIdentical($id_map->lookupDestinationIds(['test_event']), [['test_event']]);
// Test we have a body field.
$field = FieldConfig::loadByName('node', 'test_event', 'body');
......
......@@ -29,7 +29,7 @@ public function testViewModes() {
$this->assertIdentical(FALSE, is_null($view_mode), 'Preview view mode loaded.');
$this->assertIdentical('Preview', $view_mode->label(), 'View mode has correct label.');
// Test the ID map.
$this->assertIdentical(['node', 'preview'], $this->getMigration('d6_view_modes')->getIdMap()->lookupDestinationId([1]));
$this->assertIdentical([['node', 'preview']], $this->getMigration('d6_view_modes')->getIdMap()->lookupDestinationIds([1]));
}
}
......@@ -75,7 +75,7 @@ public function testUrlAlias() {
];
$path = \Drupal::service('path.alias_storage')->load($conditions);
$this->assertPath('1', $conditions, $path);
$this->assertIdentical($id_map->lookupDestinationId([$path['pid']]), ['1'], "Test IdMap");
$this->assertIdentical($id_map->lookupDestinationIds([$path['pid']]), [['1']], "Test IdMap");
$conditions = [
'source' => '/node/2',
......
......@@ -32,7 +32,7 @@ public function testTaxonomyVocabulary() {
for ($i = 0; $i < 3; $i++) {
$j = $i + 1;
$vocabulary = Vocabulary::load("vocabulary_{$j}_i_{$i}_");
$this->assertSame($this->getMigration('d6_taxonomy_vocabulary')->getIdMap()->lookupDestinationId([$j]), [$vocabulary->id()]);
$this->assertSame($this->getMigration('d6_taxonomy_vocabulary')->getIdMap()->lookupDestinationIds([$j]), [[$vocabulary->id()]]);
$this->assertSame("vocabulary $j (i=$i)", $vocabulary->label());
$this->assertSame("description of vocabulary $j (i=$i)", $vocabulary->getDescription());
$this->assertSame(4 + $i, $vocabulary->get('weight'));
......
......@@ -61,7 +61,7 @@ public function testSkipNonExistentNode() {
// according to the map table, it failed.
$migration = $this->getMigration('d6_term_node:2');
$this->executeMigration($migration);
$this->assertNull($migration->getIdMap()->lookupDestinationId(['vid' => 3])[0]);
$this->assertNull($migration->getIdMap()->lookupDestinationIds(['vid' => 3])[0][0]);
}
}
......@@ -45,7 +45,7 @@ public function testVocabularyEntityDisplay() {
$this->assertSame('entity_reference_label', $component['type']);
$this->assertSame(20, $component['weight']);
// Test the Id map.
$this->assertSame(['node', 'article', 'default', 'field_tags'], $this->getMigration('d6_vocabulary_entity_display')->getIdMap()->lookupDestinationId([4, 'article']));
$this->assertSame([['node', 'article', 'default', 'field_tags']], $this->getMigration('d6_vocabulary_entity_display')->getIdMap()->lookupDestinationIds([4, 'article']));
// Tests that a vocabulary named like a D8 base field will be migrated and
// prefixed with 'field_' to avoid conflicts.
......
......@@ -45,7 +45,7 @@ public function testVocabularyEntityFormDisplay() {
$this->assertSame('options_select', $component['type']);
$this->assertSame(20, $component['weight']);
// Test the Id map.
$this->assertSame(['node', 'article', 'default', 'field_tags'], $this->getMigration('d6_vocabulary_entity_form_display')->getIdMap()->lookupDestinationId([4, 'article']));
$this->assertSame([['node', 'article', 'default', 'field_tags']], $this->getMigration('d6_vocabulary_entity_form_display')->getIdMap()->lookupDestinationIds([4, 'article']));
// Test the term widget tags setting.
$entity_form_display = EntityFormDisplay::load('node.story.default');
......
......@@ -60,7 +60,7 @@ public function testVocabularyFieldInstance() {
$this->assertSame(['field_tags'], $settings['handler_settings']['target_bundles'], 'The target_bundles handler setting is correct.');
$this->assertSame(TRUE, $settings['handler_settings']['auto_create'], 'The "auto_create" setting is correct.');
$this->assertSame(['node', 'article', 'field_tags'], $this->getMigration('d6_vocabulary_field_instance')->getIdMap()->lookupDestinationId([4, 'article']));
$this->assertSame([['node', 'article', 'field_tags']], $this->getMigration('d6_vocabulary_field_instance')->getIdMap()->lookupDestinationIds([4, 'article']));
// Test the the field vocabulary_1_i_0_ with multilingual option,
// 'per language terms'.
......
......@@ -39,7 +39,7 @@ public function testVocabularyField() {
$this->assertSame('taxonomy_term', $settings['target_type'], "Target type is correct.");
$this->assertSame(1, $field_storage->getCardinality(), "Field cardinality in 1.");
$this->assertSame(['node', 'field_tags'], $this->getMigration('d6_vocabulary_field')->getIdMap()->lookupDestinationId([4]), "Test IdMap");
$this->assertSame([['node', 'field_tags']], $this->getMigration('d6_vocabulary_field')->getIdMap()->lookupDestinationIds([4]), "Test IdMap");
// Tests that a vocabulary named like a D8 base field will be migrated and
// prefixed with 'field_' to avoid conflicts.
......
......@@ -91,7 +91,7 @@ public function testUser() {
$roles = [RoleInterface::AUTHENTICATED_ID];
$id_map = $this->getMigration('d6_user_role')->getIdMap();
foreach ($rids as $rid) {
$role = $id_map->lookupDestinationId([$rid]);
$role = $id_map->lookupDestinationIds([$rid])[0];
$roles[] = reset($role);
}
......
......@@ -157,7 +157,7 @@ public function testUser() {
$roles = [RoleInterface::AUTHENTICATED_ID];
$id_map = $this->getMigration('d7_user_role')->getIdMap();
foreach ($rids as $rid) {
$role = $id_map->lookupDestinationId([$rid]);
$role = $id_map->lookupDestinationIds([$rid])[0];
$roles[] = reset($role);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment