Created
September 1, 2017 13:38
-
-
Save IT-Cru/866dc78a766821121c8559f08456f2ec to your computer and use it in GitHub Desktop.
DCX Integration: Optimize file create
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/modules/dcx_migration/src/Plugin/migrate/process/FileFromURL.php b/modules/dcx_migration/src/Plugin/migrate/process/FileFromURL.php | |
index c753e60..e9266ab 100644 | |
--- a/modules/dcx_migration/src/Plugin/migrate/process/FileFromURL.php | |
+++ b/modules/dcx_migration/src/Plugin/migrate/process/FileFromURL.php | |
@@ -124,14 +124,20 @@ class FileFromUrl extends ProcessPluginBase implements ContainerFactoryPluginInt | |
// Remove. | |
unlink($tmp_name); | |
- $file = File::create([ | |
- 'uri' => $uri, | |
- 'filename' => $file_name, | |
- ]); | |
- | |
- $file->save(); | |
- | |
- return $file->id(); | |
+ // Create file entity. | |
+ $file = File::create(); | |
+ $file->setFileUri($uri); | |
+ $file->setOwnerId(\Drupal::currentUser()->id()); | |
+ $file->setMimeType(\Drupal::service('file.mime_type.guesser')->guess($uri)); | |
+ $file->setFileName($file_name); | |
+ $file->setTemporary(); | |
+ | |
+ if (empty(file_validate($file))) { | |
+ $file->setPermanent(); | |
+ $file->save(); | |
+ return $file->id(); | |
+ } | |
+ return FALSE; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment