public function FileSync::importFiles in Tome 8
Imports all files from the file directory.
Overrides FileSyncInterface::importFiles
File
- modules/
tome_sync/ src/ FileSync.php, line 42
Class
- FileSync
- Handles file import and exports by keeping a file export directory in sync.
Namespace
Drupal\tome_syncCode
public function importFiles() {
$file_directory = $this
->getFileDirectory();
if (!is_dir($file_directory)) {
return;
}
/** @var \Drupal\file\FileInterface $file */
foreach ($this->fileSystem
->scanDirectory($file_directory, '/.*/') as $file) {
$destination = 'public://' . ltrim(str_replace($file_directory, '', $file->uri), '/');
$directory = dirname($destination);
$this->fileSystem
->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY);
$this->fileSystem
->copy($file->uri, $destination, FileSystemInterface::EXISTS_REPLACE);
}
}