summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2018-08-10 06:24:42 (GMT)
committerNathaniel Catchpole2018-08-10 06:25:00 (GMT)
commitdef290c1fe41805a419e006bb120db85755201e3 (patch)
tree9eb30b242abc0fdd185dc7e189ec692ca52ebc06
parent4e87836d9dead02f0ab11655fbe1752f4a26879b (diff)
Issue #2729369 by quietone, Jo Fitzgerald, maxocub, mikeryan, heddn: Remove support for migrating temporary files
(cherry picked from commit 953b7c73028e8b1e1084de9f76cb21fd74b789a5)
-rw-r--r--core/modules/file/src/Plugin/migrate/source/d6/File.php1
-rw-r--r--core/modules/file/src/Plugin/migrate/source/d7/File.php7
-rw-r--r--core/modules/file/tests/src/Kernel/Migrate/d6/MigrateFileTest.php35
-rw-r--r--core/modules/file/tests/src/Kernel/Migrate/d7/MigrateFileTest.php3
-rw-r--r--core/modules/file/tests/src/Kernel/Plugin/migrate/source/d6/FileTest.php37
-rw-r--r--core/modules/file/tests/src/Kernel/Plugin/migrate/source/d7/FileTest.php62
-rw-r--r--core/modules/migrate_drupal/tests/fixtures/drupal7.php11
-rw-r--r--core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php4
-rw-r--r--core/modules/simpletest/files/image-3.jpgbin0 -> 1831 bytes
9 files changed, 121 insertions, 39 deletions
diff --git a/core/modules/file/src/Plugin/migrate/source/d6/File.php b/core/modules/file/src/Plugin/migrate/source/d6/File.php
index 9ec4887..14a0a6d 100644
--- a/core/modules/file/src/Plugin/migrate/source/d6/File.php
+++ b/core/modules/file/src/Plugin/migrate/source/d6/File.php
@@ -42,6 +42,7 @@ class File extends DrupalSqlBase {
public function query() {
return $this->select('files', 'f')
->fields('f')
+ ->condition('filepath', '/tmp%', 'NOT LIKE')
->orderBy('timestamp')
// If two or more files have the same timestamp, they'll end up in a
// non-deterministic order. Ordering by fid (or any other unique field)
diff --git a/core/modules/file/src/Plugin/migrate/source/d7/File.php b/core/modules/file/src/Plugin/migrate/source/d7/File.php
index 5e88151..c0da770 100644
--- a/core/modules/file/src/Plugin/migrate/source/d7/File.php
+++ b/core/modules/file/src/Plugin/migrate/source/d7/File.php
@@ -43,18 +43,21 @@ class File extends DrupalSqlBase {
public function query() {
$query = $this->select('file_managed', 'f')
->fields('f')
+ ->condition('uri', 'temporary://%', 'NOT LIKE')
->orderBy('f.timestamp');
// Filter by scheme(s), if configured.
if (isset($this->configuration['scheme'])) {
$schemes = [];
+ // Remove 'temporary' scheme.
+ $valid_schemes = array_diff((array) $this->configuration['scheme'], ['temporary']);
// Accept either a single scheme, or a list.
- foreach ((array) $this->configuration['scheme'] as $scheme) {
+ foreach ((array) $valid_schemes as $scheme) {
$schemes[] = rtrim($scheme) . '://';
}
$schemes = array_map([$this->getDatabase(), 'escapeLike'], $schemes);
- // uri LIKE 'public://%' OR uri LIKE 'private://%'
+ // Add conditions, uri LIKE 'public://%' OR uri LIKE 'private://%'.
$conditions = new Condition('OR');
foreach ($schemes as $scheme) {
$conditions->condition('uri', $scheme . '%', 'LIKE');
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 989eb15..a3d4ba5 100644
--- a/core/modules/file/tests/src/Kernel/Migrate/d6/MigrateFileTest.php
+++ b/core/modules/file/tests/src/Kernel/Migrate/d6/MigrateFileTest.php
@@ -2,7 +2,6 @@
namespace Drupal\Tests\file\Kernel\Migrate\d6;
-use Drupal\Component\Utility\Random;
use Drupal\file\Entity\File;
use Drupal\file\FileInterface;
use Drupal\KernelTests\KernelTestBase;
@@ -11,7 +10,7 @@ use Drupal\Tests\migrate\Kernel\MigrateDumpAlterInterface;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
- * file migration.
+ * Test file migration.
*
* @group migrate_drupal_6
*/
@@ -68,8 +67,10 @@ class MigrateFileTest extends MigrateDrupal6TestBase implements MigrateDumpAlter
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(3, 'image-3.jpg', '1831', 'public://image-3.jpg', 'image/jpeg', '1');
$this->assertEntity(4, 'html-1.txt', '24', 'public://html-1.txt', 'text/plain', '1');
+ // Ensure temporary file was not migrated.
+ $this->assertNull(File::load(6));
$map_table = $this->getMigration('d6_file')->getIdMap()->mapTableName();
$map = \Drupal::database()
@@ -81,10 +82,9 @@ class MigrateFileTest extends MigrateDrupal6TestBase implements MigrateDumpAlter
// The 4 files from the fixture.
1 => '1',
2 => '2',
+ // The file updated in migrateDumpAlter().
3 => '3',
5 => '4',
- // The file updated in migrateDumpAlter().
- 6 => NULL,
// The file created in migrateDumpAlter().
7 => '4',
];
@@ -124,10 +124,9 @@ class MigrateFileTest extends MigrateDrupal6TestBase implements MigrateDumpAlter
// The 4 files from the fixture.
1 => '5',
2 => '6',
+ // The file updated in migrateDumpAlter().
3 => '7',
5 => '8',
- // The file updated in migrateDumpAlter().
- 6 => NULL,
// The files created in migrateDumpAlter().
7 => '8',
8 => '8',
@@ -143,32 +142,16 @@ class MigrateFileTest extends MigrateDrupal6TestBase implements MigrateDumpAlter
}
/**
- * @return string
- * A filename based upon the test.
- */
- public static function getUniqueFilename() {
- return static::$tempFilename;
- }
-
- /**
* {@inheritdoc}
*/
public static function migrateDumpAlter(KernelTestBase $test) {
- // Creates a random filename and updates the source database.
- $random = new Random();
- $temp_directory = file_directory_temp();
- file_prepare_directory($temp_directory, FILE_CREATE_DIRECTORY);
- static::$tempFilename = $test->getDatabasePrefix() . $random->name() . '.jpg';
- $file_path = $temp_directory . '/' . static::$tempFilename;
- file_put_contents($file_path, '');
-
$db = Database::getConnection('default', 'migrate');
$db->update('files')
- ->condition('fid', 6)
+ ->condition('fid', 3)
->fields([
- 'filename' => static::$tempFilename,
- 'filepath' => $file_path,
+ 'filename' => 'image-3.jpg',
+ 'filepath' => 'core/modules/simpletest/files/image-3.jpg',
])
->execute();
diff --git a/core/modules/file/tests/src/Kernel/Migrate/d7/MigrateFileTest.php b/core/modules/file/tests/src/Kernel/Migrate/d7/MigrateFileTest.php
index 38ef4ff..ea32df5 100644
--- a/core/modules/file/tests/src/Kernel/Migrate/d7/MigrateFileTest.php
+++ b/core/modules/file/tests/src/Kernel/Migrate/d7/MigrateFileTest.php
@@ -2,6 +2,7 @@
namespace Drupal\Tests\file\Kernel\Migrate\d7;
+use Drupal\file\Entity\File;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
/**
@@ -43,6 +44,8 @@ class MigrateFileTest extends MigrateDrupal7TestBase {
*/
public function testFileMigration() {
$this->assertEntity(1, 'cube.jpeg', 'public://cube.jpeg', 'image/jpeg', '3620', '1421727515', '1421727515', '1');
+ // Ensure temporary file was not migrated.
+ $this->assertNull(File::load(4));
}
}
diff --git a/core/modules/file/tests/src/Kernel/Plugin/migrate/source/d6/FileTest.php b/core/modules/file/tests/src/Kernel/Plugin/migrate/source/d6/FileTest.php
index cc8c9b3..33c430e 100644
--- a/core/modules/file/tests/src/Kernel/Plugin/migrate/source/d6/FileTest.php
+++ b/core/modules/file/tests/src/Kernel/Plugin/migrate/source/d6/FileTest.php
@@ -46,11 +46,42 @@ class FileTest extends MigrateSqlSourceTestBase {
'status' => 1,
'timestamp' => 1382255662,
],
+ [
+ 'fid' => 3,
+ 'uid' => 1,
+ 'filename' => 'migrate-test-file-3.pdf',
+ 'filepath' => '/tmp/migrate-test-file-3.pdf',
+ 'filemime' => 'application/pdf',
+ 'filesize' => 304124,
+ 'status' => 1,
+ 'timestamp' => 1382277662,
+ ],
];
- // The expected results are identical to the source data.
- $tests[0]['expected_data'] = $tests[0]['source_data']['files'];
-
+ // The expected results are the same as the source data but excluding
+ // the temporary file.
+ $tests[0]['expected_data'] = [
+ [
+ 'fid' => 1,
+ 'uid' => 1,
+ 'filename' => 'migrate-test-file-1.pdf',
+ 'filepath' => 'sites/default/files/migrate-test-file-1.pdf',
+ 'filemime' => 'application/pdf',
+ 'filesize' => 890404,
+ 'status' => 1,
+ 'timestamp' => 1382255613,
+ ],
+ [
+ 'fid' => 2,
+ 'uid' => 1,
+ 'filename' => 'migrate-test-file-2.pdf',
+ 'filepath' => 'sites/default/files/migrate-test-file-2.pdf',
+ 'filemime' => 'application/pdf',
+ 'filesize' => 204124,
+ 'status' => 1,
+ 'timestamp' => 1382255662,
+ ],
+ ];
return $tests;
}
diff --git a/core/modules/file/tests/src/Kernel/Plugin/migrate/source/d7/FileTest.php b/core/modules/file/tests/src/Kernel/Plugin/migrate/source/d7/FileTest.php
index 8ae0ec4..b588ad7 100644
--- a/core/modules/file/tests/src/Kernel/Plugin/migrate/source/d7/FileTest.php
+++ b/core/modules/file/tests/src/Kernel/Plugin/migrate/source/d7/FileTest.php
@@ -84,15 +84,14 @@ class FileTest extends MigrateSqlSourceTestBase {
],
];
- // The expected results will include only the first three files, since we
- // are configuring the plugin to filter out the file with the null URI
- // scheme.
- $tests[0]['expected_data'] = array_slice($tests[0]['source_data']['file_managed'], 0, 3);
+ // The expected results will include only the first two files, since the
+ // plugin will filter out files with either the null URI scheme or the
+ // temporary scheme.
+ $tests[0]['expected_data'] = array_slice($tests[0]['source_data']['file_managed'], 0, 2);
// The filepath property will vary by URI scheme.
$tests[0]['expected_data'][0]['filepath'] = 'sites/default/files/cube.jpeg';
$tests[0]['expected_data'][1]['filepath'] = '/path/to/private/files/cube.jpeg';
- $tests[0]['expected_data'][2]['filepath'] = '/tmp/cube.jpeg';
// Do an automatic count.
$tests[0]['expected_count'] = NULL;
@@ -102,10 +101,61 @@ class FileTest extends MigrateSqlSourceTestBase {
'constants' => [
'source_base_path' => '/path/to/files',
],
- // Only return files which use one of these URI schemes.
'scheme' => ['public', 'private', 'temporary'],
];
+ // Test getting only public files.
+ $tests[1]['source_data'] = $tests[0]['source_data'];
+
+ $tests[1]['expected_data'] = [
+ [
+ 'fid' => '1',
+ 'uid' => '1',
+ 'filename' => 'cube.jpeg',
+ 'uri' => 'public://cube.jpeg',
+ 'filemime' => 'image/jpeg',
+ 'filesize' => '3620',
+ 'status' => '1',
+ 'timestamp' => '1421727515',
+ ],
+ ];
+ // Do an automatic count.
+ $tests[1]['expected_count'] = NULL;
+
+ // Set up plugin configuration.
+ $tests[1]['configuration'] = [
+ 'constants' => [
+ 'source_base_path' => '/path/to/files',
+ ],
+ 'scheme' => ['public'],
+ ];
+
+ // Test getting only public files when configuration scheme is not an array.
+ $tests[2]['source_data'] = $tests[0]['source_data'];
+
+ $tests[2]['expected_data'] = [
+ [
+ 'fid' => '1',
+ 'uid' => '1',
+ 'filename' => 'cube.jpeg',
+ 'uri' => 'public://cube.jpeg',
+ 'filemime' => 'image/jpeg',
+ 'filesize' => '3620',
+ 'status' => '1',
+ 'timestamp' => '1421727515',
+ ],
+ ];
+ // Do an automatic count.
+ $tests[2]['expected_count'] = NULL;
+
+ // Set up plugin configuration.
+ $tests[2]['configuration'] = [
+ 'constants' => [
+ 'source_base_path' => '/path/to/files',
+ ],
+ 'scheme' => 'public',
+ ];
+
return $tests;
}
diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal7.php b/core/modules/migrate_drupal/tests/fixtures/drupal7.php
index e76ee20..3624a4a 100644
--- a/core/modules/migrate_drupal/tests/fixtures/drupal7.php
+++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php
@@ -13373,6 +13373,17 @@ $connection->insert('file_managed')
'status' => '1',
'timestamp' => '1486104045',
))
+->values(array(
+ 'fid' => '4',
+ 'uid' => '1',
+ 'filename' => 'TerokNor.txt',
+ 'uri' => 'temporary://TerokNor.txt',
+ 'filemime' => 'text/plain',
+ 'filesize' => '2369',
+ 'status' => '1',
+ 'timestamp' => '1421747516',
+))
+
->execute();
$connection->schema()->createTable('file_usage', array(
diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php
index 96aa557..d8ffd02 100644
--- a/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php
+++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php
@@ -69,7 +69,7 @@ class MigrateUpgrade6Test extends MigrateUpgradeExecuteTestBase {
'editor' => 2,
'field_config' => 89,
'field_storage_config' => 63,
- 'file' => 8,
+ 'file' => 7,
'filter_format' => 7,
'image_style' => 5,
'language_content_settings' => 3,
@@ -109,7 +109,7 @@ class MigrateUpgrade6Test extends MigrateUpgradeExecuteTestBase {
$counts['comment'] = 7;
$counts['entity_view_display'] = 55;
$counts['entity_view_mode'] = 14;
- $counts['file'] = 9;
+ $counts['file'] = 8;
$counts['menu_link_content'] = 11;
$counts['node'] = 18;
$counts['taxonomy_term'] = 9;
diff --git a/core/modules/simpletest/files/image-3.jpg b/core/modules/simpletest/files/image-3.jpg
new file mode 100644
index 0000000..ace07d0
--- /dev/null
+++ b/core/modules/simpletest/files/image-3.jpg
Binary files differ