diff -u b/core/modules/migrate/src/Plugin/migrate/destination/EntityFile.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityFile.php --- b/core/modules/migrate/src/Plugin/migrate/destination/EntityFile.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityFile.php @@ -7,12 +7,12 @@ namespace Drupal\migrate\Plugin\migrate\destination; +use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\File\FileSystemInterface; use Drupal\Core\StreamWrapper\LocalStream; use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface; -use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\migrate\Entity\MigrationInterface; use Drupal\migrate\Row; use Drupal\migrate\MigrateException; @@ -41,7 +41,7 @@ /** * {@inheritdoc} */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, TranslationInterface $translator, EntityStorageInterface $storage, array $bundles, EntityManagerInterface $entity_manager, StreamWrapperManagerInterface $stream_wrappers, FileSystemInterface $file_system) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, EntityManagerInterface $entity_manager, StreamWrapperManagerInterface $stream_wrappers, FileSystemInterface $file_system) { $configuration += array( 'source_base_path' => '', 'source_path_property' => 'filepath', @@ -51,7 +51,6 @@ ); parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $entity_manager); - $this->stringTranslation = $translator; $this->streamWrapperManager = $stream_wrappers; $this->fileSystem = $file_system; } @@ -66,7 +65,6 @@ $plugin_id, $plugin_definition, $migration, - $container->get('string_translation'), $container->get('entity.manager')->getStorage($entity_type), array_keys($container->get('entity.manager')->getBundleInfo($entity_type)), $container->get('entity.manager'), @@ -85,7 +83,7 @@ // Ensure the source file exists, if it's a local URI or path. if ($this->isLocalUri($source) && !file_exists($source)) { - throw new MigrateException($this->t('File %source does not exist.', ['%source' => $source])); + throw new MigrateException(SafeMarkup::format('File %source does not exist.', ['%source' => $source])); } // If the start and end file is exactly the same, there is nothing to do. @@ -101,7 +99,7 @@ $success = $this->writeFile($source, $destination, $replace); } else { - throw new MigrateException($this->t('Could not create directory %dir', ['%dir' => $dir])); + throw new MigrateException(SafeMarkup::format('Could not create directory %dir', ['%dir' => $dir])); } } @@ -109,7 +107,7 @@ return parent::import($row, $old_destination_id_values); } else { - throw new MigrateException($this->t('File %source could not be copied to %destination.', ['%source' => $source, '%destination' => $destination])); + throw new MigrateException(SafeMarkup::format('File %source could not be copied to %destination.', ['%source' => $source, '%destination' => $destination])); } } diff -u b/core/modules/migrate/tests/src/Unit/destination/EntityFileTest.php b/core/modules/migrate/tests/src/Unit/destination/EntityFileTest.php --- b/core/modules/migrate/tests/src/Unit/destination/EntityFileTest.php +++ b/core/modules/migrate/tests/src/Unit/destination/EntityFileTest.php @@ -39,7 +39,6 @@ public function setUp() { parent::setUp(); $this->destination = new TestEntityFile([]); - $this->destination->stringTranslation = \Drupal::getContainer()->get('string_translation'); $this->destination->streamWrapperManager = \Drupal::getContainer()->get('stream_wrapper_manager'); $this->destination->fileSystem = \Drupal::getContainer()->get('file_system'); @@ -141,11 +140,6 @@ public $configuration; /** - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - public $stringTranslation; - - /** * @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface */ public $streamWrapperManager; only in patch2: unchanged: --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateFileTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateFileTest.php @@ -8,6 +8,7 @@ namespace Drupal\migrate_drupal\Tests\d6; use Drupal\Component\Utility\Random; +use Drupal\file\FileInterface; use Drupal\migrate\MigrateExecutable; use Drupal\migrate\Tests\MigrateDumpAlterInterface; use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase; @@ -60,10 +61,15 @@ protected function setUp() { public function testFiles() { /** @var \Drupal\file\FileInterface $file */ $file = entity_load('file', 1); - $this->assertIdentical('Image1.png', $file->getFilename()); - $this->assertIdentical('39325', $file->getSize()); - $this->assertIdentical('public://image-1.png', $file->getFileUri()); - $this->assertIdentical('image/png', $file->getMimeType()); + if ($file instanceof FileInterface) { + $this->assertIdentical('Image1.png', $file->getFilename()); + $this->assertIdentical('39325', $file->getSize()); + $this->assertIdentical('public://image-1.png', $file->getFileUri()); + $this->assertIdentical('image/png', $file->getMimeType()); + } + else { + $this->fail('File 1 does not exist.'); + } // It is pointless to run the second half from MigrateDrupal6Test. if (empty($this->standalone)) { return; @@ -92,11 +98,21 @@ public function testFiles() { $executable->import(); $file = entity_load('file', 2); - $this->assertIdentical('public://core/modules/simpletest/files/image-2.jpg', $file->getFileUri()); + if ($file instanceof FileInterface) { + $this->assertIdentical('public://core/modules/simpletest/files/image-2.jpg', $file->getFileUri()); + } + else { + $this->fail('File 2 does not exist.'); + } // Ensure that a temporary file has been migrated. $file = entity_load('file', 6); - $this->assertIdentical('temporary://' . static::getUniqueFilename(), $file->getFileUri()); + if ($file instanceof FileInterface) { + $this->assertIdentical('temporary://' . static::getUniqueFilename(), $file->getFileUri()); + } + else { + $this->fail('File 6 does not exist.'); + } } /**