Skip to content

Instantly share code, notes, and snippets.

@dannylamb
Last active September 18, 2019 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dannylamb/48b4f7284e11e9df05e95cb3625f9c92 to your computer and use it in GitHub Desktop.
Save dannylamb/48b4f7284e11e9df05e95cb3625f9c92 to your computer and use it in GitHub Desktop.
Islandora CLAW - Flysystem Import Without Moving Files
$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