You are here

protected function MigrateFileUri::copyFile in Migrate 7.2

Implementation of MigrateFile::copyFile().

Parameters

$destination: Destination within Drupal.

Return value

bool TRUE if the copy succeeded, FALSE otherwise.

Overrides MigrateFile::copyFile

File

plugins/destinations/file.inc, line 397
Support for file entity as destination. Note that File Fields have their own destination in fields.inc

Class

MigrateFileUri
Handle cases where we're handed a URI, or local filespec, representing a file to be imported to Drupal.

Code

protected function copyFile($destination) {
  if ($this->urlEncode) {

    // Perform the copy operation, with a cleaned-up path.
    $this->sourcePath = self::urlencode($this->sourcePath);
  }
  try {
    $copied = copy($this->sourcePath, $destination);
    if ($copied == FALSE) {
      $migration = Migration::currentMigration();
      $migration
        ->saveMessage(t('The specified file %file could not be copied to %destination', array(
        '%file' => $this->sourcePath,
        '%destination' => $destination,
      )));
    }
    return $copied;
  } catch (Exception $e) {
    $migration = Migration::currentMigration();
    $migration
      ->saveMessage(t('The specified file %file could not be copied to %destination: "%exception_msg"', array(
      '%file' => $this->sourcePath,
      '%destination' => $destination,
      '%exception_msg' => $e
        ->getMessage(),
    )));
    return FALSE;
  }
}