diff --git a/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php index c542293..14a0a7a 100644 --- a/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php +++ b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php @@ -183,7 +183,20 @@ public static function create(ContainerInterface $container, array $configuratio * An hash containing the hashed values of the source identifiers. */ public function getSourceIDsHash(array $source_id_values) { - return hash('sha256', serialize(array_map('strval', array_values($source_id_values)))); + // When looking up the destination ID we require an array with both the + // source key and value, e.g. ['nid' => 41]. In this case, $source_id_values + // need to be ordered the same order as $this->sourceIdFields(). + // However, the Migration process plugin doesn't currently have a way to get + // the source key so we presume the values have been passed through in the + // correct order. + if (!isset($source_id_values[0])) { + $source_id_values_keyed = []; + foreach ($this->sourceIdFields() as $field_name => $source_id) { + $source_id_values_keyed[] = $source_id_values[$field_name]; + } + $source_id_values = $source_id_values_keyed; + } + return hash('sha256', serialize(array_map('strval', $source_id_values))); } /** diff --git a/core/modules/migrate/tests/src/Unit/RowTest.php b/core/modules/migrate/tests/src/Unit/RowTest.php index f0f5dad..b723fa5 100644 --- a/core/modules/migrate/tests/src/Unit/RowTest.php +++ b/core/modules/migrate/tests/src/Unit/RowTest.php @@ -201,30 +201,30 @@ public function testSourceIdValues() { */ public function testMultipleSourceIdValues() { // Set values in same order as ids. - $multi_source_ids = $this->testSourceIds + array( - 'vid' => 'Node revision', - 'type' => 'Node type', - 'langcode' => 'Node language', - ); - $multi_source_ids_values = $this->testValues + array( - 'vid' => 1, - 'type' => 'page', - 'langcode' => 'en', - ); + $multi_source_ids = $this->testSourceIds + [ + 'vid' => 'Node revision', + 'type' => 'Node type', + 'langcode' => 'Node language', + ]; + $multi_source_ids_values = $this->testValues + [ + 'vid' => 1, + 'type' => 'page', + 'langcode' => 'en', + ]; $row = new Row($multi_source_ids_values, $multi_source_ids); $this->assertSame(array_keys($multi_source_ids), array_keys($row->getSourceIdValues())); // Set values in different order. - $multi_source_ids = $this->testSourceIds + array( + $multi_source_ids = $this->testSourceIds + [ 'vid' => 'Node revision', 'type' => 'Node type', 'langcode' => 'Node language', - ); - $multi_source_ids_values = $this->testValues + array( + ]; + $multi_source_ids_values = $this->testValues + [ 'langcode' => 'en', 'type' => 'page', 'vid' => 1, - ); + ]; $row = new Row($multi_source_ids_values, $multi_source_ids); $this->assertSame(array_keys($multi_source_ids), array_keys($row->getSourceIdValues())); }