Last active
September 18, 2019 18:50
-
-
Save dannylamb/48b4f7284e11e9df05e95cb3625f9c92 to your computer and use it in GitHub Desktop.
Islandora CLAW - Flysystem Import Without Moving Files
This file contains hidden or 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
$filesystem = \Drupal::service('flysystem_factory')->getFilesystem('mydrive'); | |
$file_storage = \Drupal::service('entity_type.manager')->getStorage('file'); | |
$mime_guesser = \Drupal::service('file.mime_type.guesser'); | |
foreach($filesystem->listContents('/path/to/your/stuff') as $info) { | |
$mime = $mime_guesser->guess($info['path']); | |
$file = $file_storage->create([ | |
'uid' => 1, | |
'uri' => "mydrive://" . $info['path'], | |
'filename' => $info['filename'], | |
'filemime' => $mime, | |
'status' => FILE_STATUS_PERMANENT, | |
]); | |
$file->save(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment