You are here

public function MigrateDestinationFile::rollback in Migrate 7.2

Delete a file entry.

Parameters

array $fid: Fid to delete, arrayed.

File

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

Class

MigrateDestinationFile
Destination class implementing migration into the files table.

Code

public function rollback(array $fid) {
  migrate_instrument_start('file_load');
  $file = file_load(reset($fid));
  migrate_instrument_stop('file_load');
  if ($file) {
    migrate_instrument_start('file_delete');

    // If we're preserving files, roll our own version of file_delete() to make
    // sure we don't delete them. If we're not, make sure we do the job completely.
    $migration = Migration::currentMigration();
    $mappings = $migration
      ->getFieldMappings();
    if (isset($mappings['preserve_files'])) {

      // Assumes it's set using defaultValue
      $preserve_files = $mappings['preserve_files']
        ->getDefaultValue();
    }
    else {
      $preserve_files = FALSE;
    }
    $this
      ->prepareRollback($fid);
    if ($preserve_files) {
      $this
        ->fileDelete($file);
    }
    else {
      file_delete($file, TRUE);
    }
    $this
      ->completeRollback($fid);
    migrate_instrument_stop('file_delete');
  }
}