Commit d3181480 authored by catch's avatar catch

Issue #2826047 by heddn, Jo Fitzgerald, mikeryan, catch, alexpott: 6-8 user...

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
parent df2fd66d
......@@ -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:
-
......
......@@ -69,11 +69,30 @@ public function testFiles() {
$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 @@ public function testFiles() {
$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()));
}
/**
......
......@@ -79,7 +79,7 @@ public function testNode() {
// 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());
......
......@@ -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:
......
<?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');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment