0

I'm migrating images from URLs and I'm mapping the image field with this code:

$this->addFieldMapping('field_image', 'titlePhotos')
     ->xpath('/photo/@URL');
$this->addFieldMapping('field_image:source_dir')
     ->defaultValue(DRUPAL_ROOT . '/sites/default/files/images');
$this->addFieldMapping('field_image:file_class')
     ->defaultValue('MigrateFileUri');

I want to overwrite files if they already exit when running the migration for the first time and on update.

I'm using Drupal 7.

1 Answer 1

0

The MigrateFileUri destination has a class property which indicates what to do when collisions are encountered.

  /**
   * How to handle destination filename collisions.
   *
   * @var int
   */
  protected $fileReplace = FILE_EXISTS_RENAME;

What you want to do is, extend MigrateFileUri override $fileReplace to be FILE_EXISTS_REPLACE and then use that as your destination.

example:

class MigrateFileUriReplace extends MigrateFileUri {
  protected $fileReplace = FILE_EXISTS_REPLACE;
}

Don't forget to update your migration code.

$this->addFieldMapping('field_image:file_class')
     ->defaultValue('MigrateFileUriReplace');
1
  • Thanks! It works. Also, I found this post that was very useful.
    – Miguelos
    Commented Feb 26, 2014 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.