Community Documentation

Preventing deletion of files on rollback

Last updated October 7, 2011. Created by mikeryan on February 14, 2011.
Edited by eporama, rfay. Log in to edit this page.

If you are populating file fields on migration, and don't want the files to be deleted on rollback (e.g., you copied the files manually into the Drupal files directory and are using file_link to point to the pre-existing file), use the 'preserve_files' argument in your mapping:

<?php
    $this
->addFieldMapping('field_commerce_file_s3', 'commerce_file_s3')
      ->
arguments(array('preserve_files' => TRUE));
?>

Similarly, to keep files imported by a migration into MigrateDestinationFile, pass the 'preserve_files' option to the constructor:

<?php
    $this
->destination = new MigrateDestinationFile(array('preserve_files' => TRUE));
?>

Comments

Using file_usage_add()

I'm attempting to deal with this in a custom MigrateCommerceFileFieldHandler::buildFileArray() using:

    file_usage_add($file, 'AmazonS3', 'preexisting', $file->fid);

I am using MigrateFileFieldHandler to generate my arguments. How do I work this parameter in with that? Do I chain another argument call onto this?

Example:

    $jpg_arguments = MigrateFileFieldHandler::arguments(NULL,
      'file_link', FILE_EXISTS_RENAME, 'en', array('source_field' => 'jpg_name'),
      array('source_field' => 'jpg_filename'), array('source_field' => 'jpg_filename'));
   
    $this->addFieldMapping('field_image', 'jpg_uri')
         ->arguments($jpg_arguments);

Patrick Thurmond
pjerky.com

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 7.x
Audience
Programmers

Administration & Security Guide

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here