From 5c46a67f9adc21d2423077fee961c274043433f1 Mon Sep 17 00:00:00 2001
From: Gabor Hojtsy <gabor@hojtsy.hu>
Date: Thu, 4 May 2017 16:00:14 +0200
Subject: [PATCH] Issue #2698023 by Jo Fitzgerald, mitrpaka, mohit_aghera,
 gaurav.kapoor, heddn, edysmp, mikeryan: Get sourceid values sorted from Row

---
 .../migrate/src/Plugin/migrate/id_map/Sql.php |  2 +-
 core/modules/migrate/src/Row.php              |  5 +--
 .../migrate/tests/src/Unit/RowTest.php        | 33 +++++++++++++++++++
 3 files changed, 37 insertions(+), 3 deletions(-)

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 14a0a7abe5a6..27b756904a97 100644
--- a/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
+++ b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
@@ -174,7 +174,7 @@ public static function create(ContainerInterface $container, array $configuratio
   /**
    * Retrieves the hash of the source identifier values.
    *
-   * It is public only for testing purposes.
+   * @internal
    *
    * @param array $source_id_values
    *   The source identifiers
diff --git a/core/modules/migrate/src/Row.php b/core/modules/migrate/src/Row.php
index 2824dd92bcb5..95e7f28a0f6e 100644
--- a/core/modules/migrate/src/Row.php
+++ b/core/modules/migrate/src/Row.php
@@ -106,10 +106,11 @@ public function __construct(array $values = [], array $source_ids = [], $is_stub
    * Retrieves the values of the source identifiers.
    *
    * @return array
-   *   An array containing the values of the source identifiers.
+   *   An array containing the values of the source identifiers. Returns values
+   *   in the same order as defined in $this->sourceIds.
    */
   public function getSourceIdValues() {
-    return array_intersect_key($this->source, $this->sourceIds);
+    return array_merge($this->sourceIds, array_intersect_key($this->source, $this->sourceIds));
   }
 
   /**
diff --git a/core/modules/migrate/tests/src/Unit/RowTest.php b/core/modules/migrate/tests/src/Unit/RowTest.php
index 10d7d7d66e10..9a20bda55a28 100644
--- a/core/modules/migrate/tests/src/Unit/RowTest.php
+++ b/core/modules/migrate/tests/src/Unit/RowTest.php
@@ -192,6 +192,39 @@ public function testSourceIdValues() {
     $this->assertSame(['nid' => $this->testValues['nid']], $row->getSourceIdValues());
   }
 
+  /**
+   * Tests the multiple source IDs.
+   */
+  public function testMultipleSourceIdValues() {
+    // Set values in same order as ids.
+    $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 + [
+        'vid' => 'Node revision',
+        'type' => 'Node type',
+        'langcode' => 'Node language',
+      ];
+    $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()));
+  }
+
   /**
    * Tests getting the source property.
    *
-- 
GitLab