I'm trying to migrate a D6 node containing a Flickr photo field to a D7 Media flickr field (using the migrate d2d module).
The problem is that I'm not sure how to define that a field is a Flickr type of Media (instead of Youtube for example).

Normally when I migrate files to Media of file fields I just give the filepaths as value and make sure all the subfields are properly files, see the following snippet.

    $this->addFieldMapping('field_media', 'ps_images_filepath');
    $this->addFieldMapping('field_media:file_class')->defaultValue('MigrateFileUri');
    $this->addFieldMapping('field_media:file_replace')->defaultValue('FILE_EXISTS_REUSE');
    $this->addFieldMapping('field_media:preserve_files')->defaultValue(FALSE);
    $this->addFieldMapping('field_media:source_dir')->defaultValue('files2migrate');
    $this->addFieldMapping('field_media:display', 'field_img:list');    
    $this->addFieldMapping('field_media:description', 'ps_images_description');

In this case I will fill the ps_images_filepath and ps_images_description in the prepareRow().

But this time I have photo Id's that need to be translated to proper url's so I think I need to define it should be handled by a MigrateExtrasFileFlickr kind of class. Any tips?

Most examples use a seperate migration for these kind of files, like the Migrate Extras example for youtube files:

 $this->destination = new MigrateDestinationMedia('video',
      'MigrateExtrasFileYoutube');

But I've never understand why you would do this in a separate migration class and I'd like to integrate this into the node migration. In the first example I don't need a separate migration to migrate the images. Could anyone elaborate on this?

Comments

peteruithoven’s picture

Title: Define destination for specific field? (and why separate file migrations?) » How to define destination for specific fields? (and why use separate file migrations?)
mikeryan’s picture

Title: How to define destination for specific fields? (and why use separate file migrations?) » How to define destination for specific file bundles? (and why use separate file migrations?)
Status: Active » Postponed (maintainer needs more info)

I have a couple of reasons for preferring to define separate migrations for files.

1. It seems cleaner to me. Files are full-fledged entities, and much heavier than normal fields - having entities created as a side-effect of a different entity's migration makes it more difficult to debug, e.g. to figure out why a file field doesn't appear correctly you've got to figure out whether the problem is the creation of the entity, or its connection to the field.

2. When files are actually being copied, having the separate migration makes development quicker. I debug the file migration first, and then let it run and sit there while I work on the nodes referencing the files, repeatedly rolling back and reimporting as I refine the migration. This goes a lot slower when the node migrations are copying files (especially from remote servers).

I'm a little unclear on your initial question, but if the Flickr module is defining its own stream wrapper (as the Youtube module does with youtube://), then you definitely need a distinct implementation of MigrateFileInterface to handle that.

peteruithoven’s picture

Hi Mike,

I get your points, but I want to copy only the files that are used in the content types I'm migrating, so that might make that file migration step a lot more complex. Also I'm not sure how I would check if all the files would come over for every content type for all the fields.

Thanks for the tip on the MigrateFileInterface, I did, but it seems like Migration doesn't support different file_class subfields/arguments just yet, I've posted a issue about it here.
http://drupal.org/node/1819696

Bojhan’s picture

Status: Postponed (maintainer needs more info) » Active
mikeryan’s picture

Status: Active » Postponed (maintainer needs more info)

Actually, copying all the files is less complex than picking and choosing. But of course slower;)...

You can filter your file migration. If you're using migrate_d2d and extending DrupalFile6Migration, you can override the query() method and add an inner join to the relevant CCK table to only pull files attached via that field.

mikeryan’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

No further response.

mikeryan’s picture

Issue summary: View changes

clarification