You are here

public function FileSync::exportFile in Tome 8

Exports a file to the export directory.

Parameters

\Drupal\file\FileInterface $file: The file entity.

Overrides FileSyncInterface::exportFile

File

modules/tome_sync/src/FileSync.php, line 72

Class

FileSync
Handles file import and exports by keeping a file export directory in sync.

Namespace

Drupal\tome_sync

Code

public function exportFile(FileInterface $file) {
  $this
    ->ensureFileDirectory();
  $file_directory = $this
    ->getFileDirectory();
  if (strpos($file
    ->getFileUri(), 'public://') === 0 && file_exists($file
    ->getFileUri())) {
    $destination = $this
      ->joinPaths($file_directory, StreamWrapperManager::getTarget($file
      ->getFileUri()));
    $directory = dirname($destination);
    $this->fileSystem
      ->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY);
    $this->fileSystem
      ->copy($file
      ->getFileUri(), $destination, FileSystemInterface::EXISTS_REPLACE);
  }
}