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 @@ -20,20 +20,6 @@ class EntityFile extends EntityContentBase { /** - * Column name of the file URI. - */ - protected $uri_column; - - /** - * @inheritdoc - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager) { - parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $entity_manager, $field_type_manager); - $this->uri_column = isset($configuration['uri_column']) ? $configuration['uri_column'] : 'uri'; - } - - - /** * {@inheritdoc} */ protected function getEntity(Row $row, array $old_destination_id_values) { @@ -45,8 +31,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($this->uri_column); - $entity = $this->storage->loadByProperties([$this->uri_column => $destination]); + $destination = $row->getDestinationProperty('uri'); + $entity = $this->storage->loadByProperties(['uri' => $destination]); if ($entity) { return reset($entity); } @@ -60,11 +46,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($this->uri_column)) { + if (!$row->getDestinationProperty('uri')) { $field_definitions = $this->entityManager ->getFieldDefinitions($this->storage->getEntityTypeId(), $this->getKey('bundle')); - $value = UriItem::generateSampleValue($field_definitions[$this->uri_column]); + $value = UriItem::generateSampleValue($field_definitions['uri']); if (empty($value)) { throw new MigrateException('Stubbing failed, unable to generate value for field uri'); } @@ -73,10 +59,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[$this->uri_column]->getSetting('max_length')); + $value = Unicode::substr($value, 0, $field_definitions['uri']->getSetting('max_length')); // Create a real file, so File::preSave() can do filesize() on it. touch($value); - $row->setDestinationProperty($this->uri_column, $value); + $row->setDestinationProperty('uri', $value); } parent::processStubRow($row); } diff -u b/core/modules/file/tests/src/Unit/Plugin/migrate/process/UrlEncodeTest.php b/core/modules/file/tests/src/Unit/Plugin/migrate/process/UrlEncodeTest.php --- b/core/modules/file/tests/src/Unit/Plugin/migrate/process/UrlEncodeTest.php +++ b/core/modules/file/tests/src/Unit/Plugin/migrate/process/UrlEncodeTest.php @@ -28,13 +28,13 @@ * An array of URLs to test. */ public function urlDataProvider() { - return array( - 'A URL with no characters requiring encoding' => array('http://example.com/normal_url.html', 'http://example.com/normal_url.html'), - 'The definitive use case - encoding spaces in URLs' => array('http://example.com/url with spaces.html', 'http://example.com/url%20with%20spaces.html'), - 'Local filespecs without spaces should not be transformed' => array('/tmp/normal.txt', '/tmp/normal.txt'), - 'Local filespecs with spaces should not be transformed' => array('/tmp/with spaces.txt', '/tmp/with spaces.txt'), - 'Make sure URL characters (:, ?, &) are not encoded but others are.' => array('https://example.com/?a=b@c&d=e+f%', 'https://example.com/?a%3Db%40c&d%3De%2Bf%25'), - ); + return [ + 'A URL with no characters requiring encoding' => ['http://example.com/normal_url.html', 'http://example.com/normal_url.html'], + 'The definitive use case - encoding spaces in URLs' => ['http://example.com/url with spaces.html', 'http://example.com/url%20with%20spaces.html'], + 'Local filespecs without spaces should not be transformed' => ['/tmp/normal.txt', '/tmp/normal.txt'], + 'Local filespecs with spaces should not be transformed' => ['/tmp/with spaces.txt', '/tmp/with spaces.txt'], + 'Make sure URL characters (:, ?, &) are not encoded but others are.' => ['https://example.com/?a=b@c&d=e+f%', 'https://example.com/?a%3Db%40c&d%3De%2Bf%25'], + ]; } /** @@ -49,10 +49,10 @@ * Perform the urlencode process plugin over the given value. * * @param string $value - * Url to be encoded. + * URL to be encoded. * * @return string - * Encoded url. + * Encoded URL. */ protected function doTransform($value) { $executable = new MigrateExecutable($this->getMigration(), new MigrateMessage()); diff -u b/core/modules/migrate/tests/src/Unit/process/CopyFileTest.php b/core/modules/migrate/tests/src/Unit/process/CopyFileTest.php --- b/core/modules/migrate/tests/src/Unit/process/CopyFileTest.php +++ b/core/modules/migrate/tests/src/Unit/process/CopyFileTest.php @@ -18,7 +18,7 @@ /** * {@inheritdoc} */ - public static $modules = array('system'); + public static $modules = ['system']; /** * @var FileSystemInterface @@ -30,16 +30,7 @@ */ protected function setUp() { parent::setUp(); - $this->filesystem = $this->container->get('file_system'); - } - /** - * Test successful copies from a remote source. - */ - public function testSuccessfulRemoteCopy() { - $destination_path = 'temporary://favicon.ico'; - $this->doImport('https://www.drupal.org/favicon.ico', $destination_path); - $message = sprintf('File %s exists', $destination_path); - $this->assertTrue(is_file($destination_path), $message); + $this->fileSystem = $this->container->get('file_system'); } /** @@ -64,11 +55,11 @@ public function fileDataCopyProvider() { $file = $this->createUri(NULL, NULL, 'temporary'); $file_absolute = $this->fileSystem->realpath($file); - return array( - 'local to local copy' => array($this->root . '/core/modules/simpletest/files/image-test.jpg', 'public://file1.jpg'), - 'Temporary file using an absolute path' => array($file_absolute, 'temporary://test.jpg'), - 'Temporary file using a relative path' => array($file_absolute, 'temporary://core/modules/simpletest/files/test.jpg'), - ); + return [ + 'local to local copy' => [$this->root . '/core/modules/simpletest/files/image-test.jpg', 'public://file1.jpg'], + 'Temporary file using an absolute path' => [$file_absolute, 'temporary://test.jpg'], + 'Temporary file using a relative path' => [$file_absolute, 'temporary://core/modules/simpletest/files/test.jpg'], + ]; } /** @@ -97,11 +88,11 @@ $file_2_absolute = $this->fileSystem->realpath($file_2); $local_file = $this->createUri(NULL, NULL, 'public'); - return array( - 'Local to local copy' => array($local_file, 'public://file1.jpg'), - 'Temporary file using an absolute path.' => array($file_1_absolute, 'temporary://test.jpg'), - 'Temporary file using a relative path' => array($file_2_absolute, 'temporary://core/modules/simpletest/files/test.jpg'), - ); + return [ + 'Local to local copy' => [$local_file, 'public://file1.jpg'], + 'Temporary file using an absolute path.' => [$file_1_absolute, 'temporary://test.jpg'], + 'Temporary file using a relative path' => [$file_2_absolute, 'temporary://core/modules/simpletest/files/test.jpg'], + ]; } /**