From 95b3b17867f3691951e4fa2bc4bb0b7c21431fba Mon Sep 17 00:00:00 2001
From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org>
Date: Mon, 7 Jan 2019 11:40:36 +0000
Subject: [PATCH] Issue #3023747 by mikelutz, heddn: D6 profile migrations
 assume stubs, which fail

---
 .../src/Kernel/d6/MigrationProcessTest.php    | 43 +++++++++++++++++++
 .../src/Kernel/d7/MigrationProcessTest.php    | 43 +++++++++++++++++++
 .../user/src/Plugin/migrate/ProfileValues.php |  9 ++--
 3 files changed, 90 insertions(+), 5 deletions(-)
 create mode 100644 core/modules/migrate_drupal/tests/src/Kernel/d6/MigrationProcessTest.php
 create mode 100644 core/modules/migrate_drupal/tests/src/Kernel/d7/MigrationProcessTest.php

diff --git a/core/modules/migrate_drupal/tests/src/Kernel/d6/MigrationProcessTest.php b/core/modules/migrate_drupal/tests/src/Kernel/d6/MigrationProcessTest.php
new file mode 100644
index 000000000000..42927698266d
--- /dev/null
+++ b/core/modules/migrate_drupal/tests/src/Kernel/d6/MigrationProcessTest.php
@@ -0,0 +1,43 @@
+<?php
+
+namespace Drupal\Tests\migrate_drupal\Kernel\d6;
+
+use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait;
+
+/**
+ * Tests the getProcess() method of all Drupal 6 migrations.
+ *
+ * @group migrate_drupal
+ */
+class MigrationProcessTest extends MigrateDrupal6TestBase {
+  use FileSystemModuleDiscoveryDataProviderTrait;
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setUp() {
+    self::$modules = array_keys($this->coreModuleListDataProvider());
+    parent::setUp();
+  }
+
+  /**
+   * Tests that calling getProcess() on a migration does not throw an exception.
+   *
+   * @throws \Exception
+   */
+  public function testGetProcess() {
+    /** @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface $plugin_manager */
+    $plugin_manager = $this->container->get('plugin.manager.migration');
+    $migrations = $plugin_manager->createInstancesByTag('Drupal 6');
+    foreach ($migrations as $migration) {
+      try {
+        $process = $migration->getProcess();
+      }
+      catch (\Exception $e) {
+        $this->fail(sprintf("Migration %s process failed with error: %s", $migration->label(), $e->getMessage()));
+      }
+      $this->assertNotNull($process);
+    }
+  }
+
+}
diff --git a/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrationProcessTest.php b/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrationProcessTest.php
new file mode 100644
index 000000000000..4f3826f67e18
--- /dev/null
+++ b/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrationProcessTest.php
@@ -0,0 +1,43 @@
+<?php
+
+namespace Drupal\Tests\migrate_drupal\Kernel\d7;
+
+use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait;
+
+/**
+ * Tests the getProcess() method of all Drupal 7 migrations.
+ *
+ * @group migrate_drupal
+ */
+class MigrationProcessTest extends MigrateDrupal7TestBase {
+  use FileSystemModuleDiscoveryDataProviderTrait;
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setUp() {
+    self::$modules = array_keys($this->coreModuleListDataProvider());
+    parent::setUp();
+  }
+
+  /**
+   * Tests that calling getProcess() on a migration does not throw an exception.
+   *
+   * @throws \Exception
+   */
+  public function testGetProcess() {
+    /** @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface $plugin_manager */
+    $plugin_manager = $this->container->get('plugin.manager.migration');
+    $migrations = $plugin_manager->createInstancesByTag('Drupal 7');
+    foreach ($migrations as $migration) {
+      try {
+        $process = $migration->getProcess();
+      }
+      catch (\Exception $e) {
+        $this->fail(sprintf("Migration %s process failed with error: %s", $migration->label(), $e->getMessage()));
+      }
+      $this->assertNotNull($process);
+    }
+  }
+
+}
diff --git a/core/modules/user/src/Plugin/migrate/ProfileValues.php b/core/modules/user/src/Plugin/migrate/ProfileValues.php
index 8399436c033c..979f873f3e55 100644
--- a/core/modules/user/src/Plugin/migrate/ProfileValues.php
+++ b/core/modules/user/src/Plugin/migrate/ProfileValues.php
@@ -4,7 +4,6 @@
 
 use Drupal\migrate\Exception\RequirementsException;
 use Drupal\migrate\MigrateExecutable;
-use Drupal\migrate\MigrateSkipRowException;
 use Drupal\migrate\Plugin\Migration;
 
 /**
@@ -32,6 +31,7 @@ public function getProcess() {
       $definition['destination']['plugin'] = 'null';
       $definition['idMap']['plugin'] = 'null';
       try {
+        $this->checkRequirements();
         $profile_field_migration = $this->migrationPluginManager->createStubMigration($definition);
         $migrate_executable = new MigrateExecutable($profile_field_migration);
         $source_plugin = $profile_field_migration->getSourcePlugin();
@@ -45,6 +45,7 @@ public function getProcess() {
             [
               'migration' => 'user_profile_field',
               'source_ids' => $fid,
+              'no_stub' => TRUE,
             ];
           $plugin = $this->processPluginManager->createInstance('migration_lookup', $configuration, $profile_field_migration);
           $new_value = $plugin->transform($fid, $migrate_executable, $row, 'tmp');
@@ -52,14 +53,12 @@ public function getProcess() {
             // Set the destination to the migrated profile field name.
             $this->process[$new_value[1]] = $name;
           }
-          else {
-            throw new MigrateSkipRowException("Can't migrate source field $name.");
-          }
         }
       }
       catch (RequirementsException $e) {
         // The checkRequirements() call will fail when the profile module does
-        // not exist on the source site.
+        // not exist on the source site, or if the required migrations have not
+        // yet run.
       }
     }
     return parent::getProcess();
-- 
GitLab