function FileCopy::writeFile

Same name and namespace in other branches
  1. 9 core/modules/migrate/src/Plugin/migrate/process/FileCopy.php \Drupal\migrate\Plugin\migrate\process\FileCopy::writeFile()
  2. 8.9.x core/modules/migrate/src/Plugin/migrate/process/FileCopy.php \Drupal\migrate\Plugin\migrate\process\FileCopy::writeFile()
  3. 11.x 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.

\Drupal\Core\File\FileExists|int $fileExists: (optional) FileExists::Replace (default) or FileExists::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 175

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, FileExists|int $fileExists = FileExists::Replace) {
  if (!$fileExists instanceof FileExists) {
    // @phpstan-ignore-next-line
    $fileExists = FileExists::fromLegacyInt($fileExists, __METHOD__);
  }
  // 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, $fileExists) === FALSE) {
    return $destination;
  }
  try {
    if ($this->configuration['move']) {
      return $this->fileSystem
        ->move($source, $destination, $fileExists);
    }
    else {
      return $this->fileSystem
        ->copy($source, $destination, $fileExists);
    }
  } catch (FileException $e) {
    return FALSE;
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.