From c1b5d37dfae52daf7e7afd44c3503b3e5ba87f81 Mon Sep 17 00:00:00 2001
From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org>
Date: Mon, 7 Mar 2016 11:46:48 +0900
Subject: [PATCH] Issue #2681505 by benjy: Arbitrary files are created when
 migrating users with an empty picture

---
 .../migrate_drupal_ui/src/Tests/d6/MigrateUpgrade6Test.php    | 2 +-
 core/modules/user/migration_templates/d6_user.yml             | 1 +
 core/modules/user/src/Tests/Migrate/d6/MigrateUserTest.php    | 4 ++++
 3 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/core/modules/migrate_drupal_ui/src/Tests/d6/MigrateUpgrade6Test.php b/core/modules/migrate_drupal_ui/src/Tests/d6/MigrateUpgrade6Test.php
index 693547081e76..a4137176a389 100644
--- a/core/modules/migrate_drupal_ui/src/Tests/d6/MigrateUpgrade6Test.php
+++ b/core/modules/migrate_drupal_ui/src/Tests/d6/MigrateUpgrade6Test.php
@@ -47,7 +47,7 @@ protected function getEntityCounts() {
       'editor' => 2,
       'field_config' => 61,
       'field_storage_config' => 42,
-      'file' => 4,
+      'file' => 0,
       'filter_format' => 8,
       'image_style' => 5,
       'migration' => 105,
diff --git a/core/modules/user/migration_templates/d6_user.yml b/core/modules/user/migration_templates/d6_user.yml
index 6d5795beb132..bf6ec2aded2e 100644
--- a/core/modules/user/migration_templates/d6_user.yml
+++ b/core/modules/user/migration_templates/d6_user.yml
@@ -26,6 +26,7 @@ process:
     plugin: migration
     migration: d6_user_picture_file
     source: uid
+    no_stub: true
 destination:
   plugin: entity:user
   md5_passwords: true
diff --git a/core/modules/user/src/Tests/Migrate/d6/MigrateUserTest.php b/core/modules/user/src/Tests/Migrate/d6/MigrateUserTest.php
index eb94627c60a1..e6d0bd7e45e4 100644
--- a/core/modules/user/src/Tests/Migrate/d6/MigrateUserTest.php
+++ b/core/modules/user/src/Tests/Migrate/d6/MigrateUserTest.php
@@ -117,6 +117,10 @@ public function testUser() {
         $file = File::load($user->user_picture->target_id);
         $this->assertIdentical(basename($source->picture), $file->getFilename());
       }
+      else {
+        // Ensure the user does not have a picture.
+        $this->assertFalse($user->user_picture->target_id, sprintf('User %s does not have a picture', $user->id()));
+      }
 
       // Use the API to check if the password has been salted and re-hashed to
       // conform to Drupal >= 7 for non-admin users.
-- 
GitLab