diff -u b/core/modules/file/migration_templates/d6_file.yml b/core/modules/file/migration_templates/d6_file.yml --- b/core/modules/file/migration_templates/d6_file.yml +++ b/core/modules/file/migration_templates/d6_file.yml @@ -1,17 +1,23 @@ -# Every migration that saves into {file_managed} must have the d6_file -# migration as an optional dependency to ensure d6_file runs first. +# Every migration that references a file by fid should specify this migration +# as an optional dependency. id: d6_file label: Files migration_tags: - Drupal 6 source: plugin: d6_file + constants: + # source_base_path must be set by the tool configuring this migration. It + # represents the fully qualified path relative to which uris in the files + # table are specified, and must end with a /. + source_base_path: '' process: fid: fid filename: filename source_full_path: - - plugin: d6_file_source + plugin: concat + delimiter: / source: - constants/source_base_path - filepath diff -u b/core/modules/file/migration_templates/d7_file.yml b/core/modules/file/migration_templates/d7_file.yml --- b/core/modules/file/migration_templates/d7_file.yml +++ b/core/modules/file/migration_templates/d7_file.yml @@ -6,6 +6,11 @@ - Drupal 7 source: plugin: d7_file + constants: + # source_base_path must be set by the tool configuring this migration. It + # represents the fully qualified path relative to which uris in the files + # table are specified, and must end with a /. + source_base_path: '' process: fid: fid filename: filename diff -u b/core/modules/file/src/Plugin/migrate/destination/EntityFile.php b/core/modules/file/src/Plugin/migrate/destination/EntityFile.php --- b/core/modules/file/src/Plugin/migrate/destination/EntityFile.php +++ b/core/modules/file/src/Plugin/migrate/destination/EntityFile.php @@ -16,6 +16,11 @@ class EntityFile extends EntityContentBase { /** + * Column name of the file URI. + */ + const URI_COLUMN = 'uri'; + + /** * {@inheritdoc} */ protected function getEntity(Row $row, array $old_destination_id_values) { @@ -27,8 +32,8 @@ // By default the entity key (fid) would be used, but we want to make sure // we're loading the matching uri. - $destination = $row->getDestinationProperty('uri'); - $entity = $this->storage->loadByProperties(['uri' => $destination]); + $destination = $row->getDestinationProperty(static::URI_COLUMN); + $entity = $this->storage->loadByProperties([static::URI_COLUMN => $destination]); if ($entity) { return reset($entity); } @@ -42,11 +47,11 @@ */ protected function processStubRow(Row $row) { // We stub the uri value ourselves so we can create a real stub file for it. - if (!$row->getDestinationProperty('uri')) { + if (!$row->getDestinationProperty(static::URI_COLUMN)) { $field_definitions = $this->entityManager ->getFieldDefinitions($this->storage->getEntityTypeId(), $this->getKey('bundle')); - $value = UriItem::generateSampleValue($field_definitions['uri']); + $value = UriItem::generateSampleValue($field_definitions[static::URI_COLUMN]); if (empty($value)) { throw new MigrateException('Stubbing failed, unable to generate value for field uri'); } @@ -55,10 +60,10 @@ // Make it into a proper public file uri, stripping off the existing // scheme if present. $value = 'public://' . preg_replace('|^[a-z]+://|i', '', $value); - $value = Unicode::substr($value, 0, $field_definitions['uri']->getSetting('max_length')); + $value = Unicode::substr($value, 0, $field_definitions[static::URI_COLUMN]->getSetting('max_length')); // Create a real file, so File::preSave() can do filesize() on it. touch($value); - $row->setDestinationProperty('uri', $value); + $row->setDestinationProperty(static::URI_COLUMN, $value); } parent::processStubRow($row); } reverted: --- b/core/modules/file/src/Plugin/migrate/process/d6/FileSource.php +++ /dev/null @@ -1,32 +0,0 @@ -getSourceConfiguration(); $source['site_path'] = 'core/modules/simpletest'; - $source['constants']['source_base_path'] = ''; + $source['constants']['source_base_path'] = DRUPAL_ROOT . '/'; $migration->set('source', $source); } } diff -u b/core/modules/file/tests/src/Kernel/Migrate/d6/MigrateFileTest.php b/core/modules/file/tests/src/Kernel/Migrate/d6/MigrateFileTest.php --- b/core/modules/file/tests/src/Kernel/Migrate/d6/MigrateFileTest.php +++ b/core/modules/file/tests/src/Kernel/Migrate/d6/MigrateFileTest.php @@ -93,10 +93,6 @@ $file = File::load(2); $this->assertIdentical('public://core/modules/simpletest/files/image-2.jpg', $file->getFileUri()); - // Ensure that a temporary file has been migrated. - $file = File::load(6); - $this->assertIdentical('temporary://' . static::getUniqueFilename(), $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)); diff -u b/core/modules/user/migration_templates/d6_user_picture_file.yml b/core/modules/user/migration_templates/d6_user_picture_file.yml --- b/core/modules/user/migration_templates/d6_user_picture_file.yml +++ b/core/modules/user/migration_templates/d6_user_picture_file.yml @@ -6,6 +6,11 @@ plugin: d6_user_picture_file constants: is_public: true + # source_base_path must be set by the tool configuring this migration. It + # represents the fully qualified path relative to which uris in the files + # table are specified, and must end with a /. + source_base_path: '' + source_base_path: '' process: filename: filename uid: uid @@ -34,6 +39,6 @@ source_path_property: picture migration_dependencies: - # Every migration that saves into {file_managed} must have the d6_file - # migration as an optional dependency to ensure it runs first. + # Every migration that references a file by fid should specify d6_file as an + # optional dependency. optional: - d6_file