From a809a15ece3b2af3f9b87d1889feef114ea33864 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Tue, 10 Apr 2018 12:26:52 +0100
Subject: [PATCH] Issue #2945563 by maxocub, heddn: Migration dependencies are
 not set when using the migration_lookup or iterator process plugins

---
 core/modules/migrate/src/Plugin/Migration.php | 11 +++++----
 .../tests/src/Kernel/Plugin/MigrationTest.php | 24 ++++++++++++++++++-
 2 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/core/modules/migrate/src/Plugin/Migration.php b/core/modules/migrate/src/Plugin/Migration.php
index cc8d804da5e5..3007815d041f 100644
--- a/core/modules/migrate/src/Plugin/Migration.php
+++ b/core/modules/migrate/src/Plugin/Migration.php
@@ -620,19 +620,22 @@ public function getMigrationDependencies() {
   }
 
   /**
-   * Find migration dependencies from the migration and the iterator plugins.
+   * Find migration dependencies from migration_lookup and sub_process plugins.
+   *
+   * @param array $process
+   *   A process configuration array.
    *
-   * @param $process
    * @return array
+   *   The migration dependencies.
    */
   protected function findMigrationDependencies($process) {
     $return = [];
     foreach ($this->getProcessNormalized($process) as $process_pipeline) {
       foreach ($process_pipeline as $plugin_configuration) {
-        if ($plugin_configuration['plugin'] == 'migration') {
+        if (in_array($plugin_configuration['plugin'], ['migration', 'migration_lookup'], TRUE)) {
           $return = array_merge($return, (array) $plugin_configuration['migration']);
         }
-        if ($plugin_configuration['plugin'] == 'sub_process') {
+        if (in_array($plugin_configuration['plugin'], ['iterator', 'sub_process'], TRUE)) {
           $return = array_merge($return, $this->findMigrationDependencies($plugin_configuration['process']));
         }
       }
diff --git a/core/modules/migrate/tests/src/Kernel/Plugin/MigrationTest.php b/core/modules/migrate/tests/src/Kernel/Plugin/MigrationTest.php
index c2cec4cff6e3..287860a36a0a 100644
--- a/core/modules/migrate/tests/src/Kernel/Plugin/MigrationTest.php
+++ b/core/modules/migrate/tests/src/Kernel/Plugin/MigrationTest.php
@@ -50,10 +50,32 @@ public function testGetMigrationDependencies() {
             ],
           ],
         ],
+        'f4' => [
+          'plugin' => 'migration_lookup',
+          'migration' => 'm3'
+        ],
+        'f5' => [
+          'plugin' => 'sub_process',
+          'process' => [
+            'target_id' => [
+              'plugin' => 'migration_lookup',
+              'migration' => 'm4',
+            ],
+          ],
+        ],
+        'f6' => [
+          'plugin' => 'iterator',
+          'process' => [
+            'target_id' => [
+              'plugin' => 'migration_lookup',
+              'migration' => 'm5',
+            ],
+          ],
+        ],
       ],
     ];
     $migration = $plugin_manager->createStubMigration($plugin_definition);
-    $this->assertSame(['required' => [], 'optional' => ['m1', 'm2']], $migration->getMigrationDependencies());
+    $this->assertSame(['required' => [], 'optional' => ['m1', 'm2', 'm3', 'm4', 'm5']], $migration->getMigrationDependencies());
   }
 
   /**
-- 
GitLab