I'm working on a D6->D7 site migration, and I'm having problems trying to figure out how to do a couple things with the migration of some of the files. An added wrinkle in this migration is that I'm moving the storage of the files from the local server to Amazon S3 using the S3FS module (which is really slick, BTW). The source D6 blog content type has two image fields - field_mainphoto and field_thumbailphoto. I would like to combine these fields into one multi-value image field in the blog content type in the D7 site titled field_images. The file storage locations for the two fields are main_photos/[site-date-yyyy]/[site-date-month] and thumbnail_photos/[site-date-yyyy]/[site-date-month]. The new field_images will have a storage location of images/[site-date-yyyy]/[site-date-month]. Therefore, what I need to do is twofold:

  1. Change the destination directory from main_photos/ and thumbnail_photos/ to images/.
  2. Combine the data from these two image fields into one image field.

In the interest of asking one question per post, this one is limited to the first one. I've been looking through all of the documentation, and the shortest and easiest way would be to implement an override of the prepare() method, and modify $entity->destination_dir. The only thing I don't like is that it's modifying a string. Do I need to go as far as overriding MigrateDestinationFile or MigrateFileUri, or is there a simpler way to do this?



To avoid future situations like this, here is what I came up with:

  public function prepare($entity, stdClass $row) {
    // Change the destination directory for the field_mainphoto and
    // field_thumbmailphoto files to be /images.
    foreach (array('main_photos', 'thumbnail_photos', 'video_thumbnails') as $dir) {
      if (substr($entity->destination_file, 1, strlen($dir)) == $dir) {
        $entity->destination_file = str_replace($dir,'images', $entity->destination_file);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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