You are here

protected function FileCopy::writeFile in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/migrate/src/Plugin/migrate/process/FileCopy.php \Drupal\migrate\Plugin\migrate\process\FileCopy::writeFile()
  2. 9 core/modules/migrate/src/Plugin/migrate/process/FileCopy.php \Drupal\migrate\Plugin\migrate\process\FileCopy::writeFile()

Tries to move or copy a file.

Parameters

string $source: The source path or URI.

string $destination: The destination path or URI.

int $replace: (optional) FileSystemInterface::EXISTS_REPLACE (default) or FileSystemInterface::EXISTS_RENAME.

Return value

string|bool File destination on success, FALSE on failure.

1 call to FileCopy::writeFile()
FileCopy::transform in core/modules/migrate/src/Plugin/migrate/process/FileCopy.php
Performs the associated process.

File

core/modules/migrate/src/Plugin/migrate/process/FileCopy.php, line 176

Class

FileCopy
Copies or moves a local file from one place into another.

Namespace

Drupal\migrate\Plugin\migrate\process

Code

protected function writeFile($source, $destination, $replace = FileSystemInterface::EXISTS_REPLACE) {

  // Check if there is a destination available for copying. If there isn't,
  // it already exists at the destination and the replace flag tells us to not
  // replace it. In that case, return the original destination.
  if ($this->fileSystem
    ->getDestinationFilename($destination, $replace) === FALSE) {
    return $destination;
  }
  try {
    if ($this->configuration['move']) {
      return $this->fileSystem
        ->move($source, $destination, $replace);
    }
    else {
      return $this->fileSystem
        ->copy($source, $destination, $replace);
    }
  } catch (FileException $e) {
    return FALSE;
  }
}