The preserve_files argument is supposed to keep files from being deleted upon rollback if set to true like so:

$this->addFieldMapping('field_my_field:preserve_files')
          ->defaultValue(TRUE);

But this isn't working if you're using the MigrateFileUriAsIs destination.

$this->addFieldMapping('field_my_field:file_class')
        ->defaultValue('MigrateFileUriAsIs');

I'm following up with a patch.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mariacha1’s picture

Status: Active » Needs review
FileSize
500 bytes

Here's the patch

jcandan’s picture

this patch works. tested locally, and very pleased. please commit to 7.x-2.6-rc1.

mikeryan’s picture

Status: Needs review » Postponed (maintainer needs more info)

The patch looks harmless enough - but can you explain the use case? The MigrateFileUriAsIs class simply copies URIs (which I would expect to be remote - http://example.com/foobar etc.), it does not copy/create any files on the destination side so I would not expect there to be any files to be accidentally deleted. Are you manually copying files into the Drupal files directory and copying relative references directly with MigrateFileUriAsIs? In that case I would use MigrateFileUri with preserve_files set to TRUE and file_replace set to MigrateFile::FILE_EXISTS_REUSE.

pifagor’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)