How can I override images on migration? I'm migrating images from URLs and I'm mapping the image field with this code:

$this-&gt;addFieldMapping('field_image', 'titlePhotos')
     -&gt;xpath('/photo/@URL');
$this-&gt;addFieldMapping('field_image:source_dir')
     -&gt;defaultValue(DRUPAL_ROOT . '/sites/default/files/images');
$this-&gt;addFieldMapping('field_image:file_class')
     -&gt;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.
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-&gt;addFieldMapping('field_image:file_class')
     -&gt;defaultValue('MigrateFileUriReplace');