diff -u b/core/modules/file/file.module b/core/modules/file/file.module --- b/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -168,9 +168,9 @@ */ function file_move(File $file, $destination = NULL) { // Move the file. + $source = $file->createDuplicate(); if ($uri = file_unmanaged_move($file->getFileUri(), $destination, FILE_CHECK_EXISTS_DB_FS)) { // Update the entity with the new URI. - $source = clone $file; $file->setFileUri($uri); // If $destination is supplied and is not a directory, extract the filename. diff -u b/core/modules/file/src/Tests/MoveTest.php b/core/modules/file/src/Tests/MoveTest.php --- b/core/modules/file/src/Tests/MoveTest.php +++ b/core/modules/file/src/Tests/MoveTest.php @@ -26,7 +26,7 @@ // Check the return status and that the contents changed. $this->assertTrue($result, 'File moved successfully.'); - $this->assertEqual($file->filename, drupal_basename($desired_filepath), t('The moved file entity has the new filename.')); + $this->assertEqual($file->getFilename(), drupal_basename($desired_filepath), t('The moved file entity has the new filename.')); $this->assertFalse(file_exists($old_file->getFileUri())); $this->assertEqual($contents, file_get_contents($file->getFileUri()), t('Contents of file correctly written.')); @@ -58,7 +58,7 @@ // Check the return status and that the contents changed. $this->assertTrue($result, 'File moved successfully.'); - $this->assertEqual($file->filename, drupal_basename($target->getFileUri()), t('The moved file entity has the new filename.')); + $this->assertEqual($file->getFilename(), drupal_basename($target->getFileUri()), t('The moved file entity has the new filename.')); $this->assertFalse(file_exists($old_file->getFileUri())); $this->assertEqual($contents, file_get_contents($file->getFileUri()), t('Contents of file correctly written.')); @@ -93,7 +93,7 @@ // Check the return status and that the contents changed. $this->assertTrue($result, 'File moved successfully.'); - $this->assertEqual($file->filename, drupal_basename($target->getFileUri()), t('The moved file entity has the new filename.')); + $this->assertEqual($file->getFilename(), drupal_basename($target->getFileUri()), t('The moved file entity has the new filename.')); $this->assertFalse(file_exists($old_file->getFileUri())); $this->assertEqual($contents, file_get_contents($file->getFileUri()), t('Contents of file correctly written.')); @@ -118,7 +118,7 @@ // Setup a file to overwrite. $contents = $this->randomMachineName(10); $file = $this->createFile(NULL, $contents); - $target_uri = file_unmanaged_copy($file->getFileUri(), 'public://' . $this->randomName()); + $target_uri = file_unmanaged_copy($file->getFileUri(), 'public://' . $this->randomMachineName()); $this->assertTrue(file_exists($target_uri), t('Target file exists on filesystem.')); $old_file = clone $file; @@ -126,7 +126,7 @@ // Check the return status and that the contents changed. $this->assertTrue($result, t('File moved successfully.')); - $this->assertEqual($file->filename, drupal_basename($target_uri), t('The moved file entity has the new filename.')); + $this->assertEqual($file->getFilename(), drupal_basename($target_uri), t('The moved file entity has the new filename.')); $this->assertFalse(file_exists($old_file->getFileUri())); $this->assertEqual($contents, file_get_contents($file->getFileUri()), t('Contents of file correctly written.')); @@ -134,7 +134,7 @@ $this->assertFileHooksCalled(array('move', 'load', 'update')); // Compare the returned value to what made it into the database. - $this->assertFileUnchanged($file, file_load($file->is(), TRUE)); + $this->assertFileUnchanged($file, file_load($file->id(), TRUE)); // Compare the source and results. $this->assertEqual($old_file->id(), $file->id(), t("Returned file's id matches the source.")); 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 @@ -74,7 +74,7 @@ else { // Determine whether we can perform this operation based on overwrite rules. $original_destination = $destination; - $destination = file_destination($destination, $replace); + $destination = file_uri_prepare($destination, $replace); if ($destination === FALSE) { throw new MigrateException(t('File %file could not be copied because a file by that name already exists in the destination directory (%destination)', array('%file' => $source, '%destination' => $original_destination))); }