summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2017-03-27 14:39:52 (GMT)
committerNathaniel Catchpole2017-03-27 14:39:52 (GMT)
commitd31814809159cb89797aa02bd23cbc652c76d6ef (patch)
tree92a4db57ce9a3213a9936957f43ba1ecad9ba9d7
parentdf2fd66d5999884504ab1d66f921aa6d0bf73711 (diff)
Issue #2826047 by heddn, Jo Fitzgerald, mikeryan, catch, alexpott: 6-8 user picture migration must create new fids, which can conflict with fids used by other migrations
-rw-r--r--core/modules/file/migration_templates/d6_file.yml7
-rw-r--r--core/modules/file/tests/src/Kernel/Migrate/d6/MigrateFileTest.php56
-rw-r--r--core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTest.php2
-rw-r--r--core/modules/user/migration_templates/d6_user_picture_file.yml3
-rw-r--r--core/modules/user/tests/src/Kernel/Migrate/d6/MigrateUserPictureD6FileTest.php69
5 files changed, 124 insertions, 13 deletions
diff --git a/core/modules/file/migration_templates/d6_file.yml b/core/modules/file/migration_templates/d6_file.yml
index 11d6197..c25f63f 100644
--- a/core/modules/file/migration_templates/d6_file.yml
+++ b/core/modules/file/migration_templates/d6_file.yml
@@ -14,9 +14,10 @@ source:
source_base_path: ''
process:
# If you are using both this migration and d6_user_picture_file in a custom
- # migration and executing migrations incrementally, it is recommended that
- # you remove the fid mapping here to avoid potential ID conflicts.
- fid: fid
+ # migration and executing migrations incrementally, it is strongly
+ # recommended that you remove the fid mapping to avoid potential ID
+ # conflicts. For that reason, this mapping is commented out by default.
+ # fid: fid
filename: filename
source_full_path:
-
diff --git a/core/modules/file/tests/src/Kernel/Migrate/d6/MigrateFileTest.php b/core/modules/file/tests/src/Kernel/Migrate/d6/MigrateFileTest.php
index 024db21..989eb15 100644
--- a/core/modules/file/tests/src/Kernel/Migrate/d6/MigrateFileTest.php
+++ b/core/modules/file/tests/src/Kernel/Migrate/d6/MigrateFileTest.php
@@ -69,11 +69,30 @@ class MigrateFileTest extends MigrateDrupal6TestBase implements MigrateDumpAlter
$this->assertEntity(1, 'Image1.png', '39325', 'public://image-1.png', 'image/png', '1');
$this->assertEntity(2, 'Image2.jpg', '1831', 'public://image-2.jpg', 'image/jpeg', '1');
$this->assertEntity(3, 'Image-test.gif', '183', 'public://image-test.gif', 'image/jpeg', '1');
- $this->assertEntity(5, 'html-1.txt', '24', 'public://html-1.txt', 'text/plain', '1');
+ $this->assertEntity(4, 'html-1.txt', '24', 'public://html-1.txt', 'text/plain', '1');
+
+ $map_table = $this->getMigration('d6_file')->getIdMap()->mapTableName();
+ $map = \Drupal::database()
+ ->select($map_table, 'm')
+ ->fields('m', ['sourceid1', 'destid1'])
+ ->execute()
+ ->fetchAllKeyed();
+ $map_expected = [
+ // The 4 files from the fixture.
+ 1 => '1',
+ 2 => '2',
+ 3 => '3',
+ 5 => '4',
+ // The file updated in migrateDumpAlter().
+ 6 => NULL,
+ // The file created in migrateDumpAlter().
+ 7 => '4',
+ ];
+ $this->assertEquals($map_expected, $map);
// Test that we can re-import and also test with file_directory_path set.
\Drupal::database()
- ->truncate($this->getMigration('d6_file')->getIdMap()->mapTableName())
+ ->truncate($map_table)
->execute();
// Update the file_directory_path.
@@ -90,12 +109,37 @@ class MigrateFileTest extends MigrateDrupal6TestBase implements MigrateDumpAlter
$this->executeMigration('d6_file');
- $file = File::load(2);
+ // File 2, when migrated for the second time, is treated as a different file
+ // (due to having a different uri this time) and is given fid 6.
+ $file = File::load(6);
$this->assertIdentical('public://core/modules/simpletest/files/image-2.jpg', $file->getFileUri());
- // File 7, created in static::migrateDumpAlter(), shares a path with
- // file 5, which means it should be skipped entirely.
- $this->assertNull(File::load(7));
+ $map_table = $this->getMigration('d6_file')->getIdMap()->mapTableName();
+ $map = \Drupal::database()
+ ->select($map_table, 'm')
+ ->fields('m', ['sourceid1', 'destid1'])
+ ->execute()
+ ->fetchAllKeyed();
+ $map_expected = [
+ // The 4 files from the fixture.
+ 1 => '5',
+ 2 => '6',
+ 3 => '7',
+ 5 => '8',
+ // The file updated in migrateDumpAlter().
+ 6 => NULL,
+ // The files created in migrateDumpAlter().
+ 7 => '8',
+ 8 => '8',
+ ];
+ $this->assertEquals($map_expected, $map);
+
+ // File 6, created in static::migrateDumpAlter(), shares a path with
+ // file 4, which means it should be skipped entirely. If it was migrated
+ // then it would have an fid of 9.
+ $this->assertNull(File::load(9));
+
+ $this->assertEquals(8, count(File::loadMultiple()));
}
/**
diff --git a/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTest.php b/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTest.php
index 1409648..a0365e0 100644
--- a/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTest.php
+++ b/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTest.php
@@ -79,7 +79,7 @@ class MigrateNodeTest extends MigrateNodeTestBase {
// Test the file field meta.
$this->assertIdentical('desc', $node->field_test_filefield->description);
- $this->assertIdentical('5', $node->field_test_filefield->target_id);
+ $this->assertIdentical('4', $node->field_test_filefield->target_id);
$node = Node::load(2);
$this->assertIdentical('Test title rev 3', $node->getTitle());
diff --git a/core/modules/user/migration_templates/d6_user_picture_file.yml b/core/modules/user/migration_templates/d6_user_picture_file.yml
index d367f33..3518d7a 100644
--- a/core/modules/user/migration_templates/d6_user_picture_file.yml
+++ b/core/modules/user/migration_templates/d6_user_picture_file.yml
@@ -11,9 +11,6 @@ source:
# table are specified, and must end with a /.
source_base_path: ''
process:
- # If you are using both this migration and d6_file in a custom migration
- # and executing migrations incrementally, it is recommended that you
- # remove the fid mapping from d6_file to avoid potential ID conflicts.
filename: filename
uid: uid
source_full_path:
diff --git a/core/modules/user/tests/src/Kernel/Migrate/d6/MigrateUserPictureD6FileTest.php b/core/modules/user/tests/src/Kernel/Migrate/d6/MigrateUserPictureD6FileTest.php
new file mode 100644
index 0000000..1bef370
--- /dev/null
+++ b/core/modules/user/tests/src/Kernel/Migrate/d6/MigrateUserPictureD6FileTest.php
@@ -0,0 +1,69 @@
+<?php
+
+namespace Drupal\Tests\user\Kernel\Migrate\d6;
+
+use Drupal\file\Entity\File;
+use Drupal\file\FileInterface;
+use Drupal\Tests\file\Kernel\Migrate\d6\FileMigrationTestTrait;
+use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
+
+/**
+ * User pictures migration.
+ *
+ * @group migrate_drupal_6
+ */
+class MigrateUserPictureD6FileTest extends MigrateDrupal6TestBase {
+
+ use FileMigrationTestTrait;
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUp() {
+ parent::setUp();
+
+ $this->installEntitySchema('file');
+ $this->executeMigration('d6_user_picture_file');
+ $this->setUpMigratedFiles();
+ }
+
+ /**
+ * Asserts a file entity.
+ *
+ * @param int $fid
+ * The file ID.
+ * @param string $name
+ * The expected file name.
+ * @param int $size
+ * The expected file size.
+ * @param string $uri
+ * The expected file URI.
+ * @param string $type
+ * The expected MIME type.
+ * @param int $uid
+ * The expected file owner ID.
+ */
+ protected function assertEntity($fid, $name, $size, $uri, $type, $uid) {
+ /** @var \Drupal\file\FileInterface $file */
+ $file = File::load($fid);
+ $this->assertInstanceOf(FileInterface::class, $file);
+ $this->assertSame($name, $file->getFilename());
+ $this->assertSame($size, $file->getSize());
+ $this->assertSame($uri, $file->getFileUri());
+ $this->assertSame($type, $file->getMimeType());
+ $this->assertSame($uid, $file->getOwnerId());
+ }
+
+ /**
+ * Tests the D6 user pictures migration in combination with D6 file.
+ */
+ public function testUserPicturesWithD6File() {
+ $this->assertEntity(1, 'image-test.jpg', '1901', 'public://image-test.jpg', 'image/jpeg', '2');
+ $this->assertEntity(2, 'image-test.png', '125', 'public://image-test.png', 'image/png', '8');
+ $this->assertEntity(3, 'Image1.png', '39325', 'public://image-1.png', 'image/png', '1');
+ $this->assertEntity(4, 'Image2.jpg', '1831', 'public://image-2.jpg', 'image/jpeg', '1');
+ $this->assertEntity(5, 'Image-test.gif', '183', 'public://image-test.gif', 'image/jpeg', '1');
+ $this->assertEntity(6, 'html-1.txt', '24', 'public://html-1.txt', 'text/plain', '1');
+ }
+
+}