When I attempt to migrate multiple files using Migrate 2.4's file handling, I get an error; "ltrim() expects parameter 1 to be string, array given File /.../sites/all/modules/contrib/migrate/plugins/destinations/file.inc, line 212".
The array looks like this:
field_thumbnail (Array, 4 elements)
0 (String, 48 characters ) sites/default/files/gaza-201106-ebaba-0025_0.jpg
1 (String, 34 characters ) sites/default/files/dsc_0110_0.jpg
2 (String, 34 characters ) sites/default/files/dsc_0098_0.jpg
3 (String, 34 characters ) sites/default/files/dsc_0015_0.jpg
The field mapping looks like this:
$this->addFieldMapping( 'field_thumbnail', 'field_thumbnail' );
$this->addFieldMapping( 'field_thumbnail:source_dir' )->defaultValue( MC_MIGRATION_FILES_DIRECTORY );
$this->addFieldMapping( 'field_thumbnail:destination_file', 'field_thumbnail_dest' ); // similar array to field_thumbnail less the sites/default/files/
$this->addFieldMapping( 'field_thumbnail:file_replace' )->defaultValue( MigrateFile::FILE_EXISTS_REUSE );
$this->addFieldMapping( 'field_thumbnail:preserve_files' )->defaultValue( FALSE );
$this->addFieldMapping( 'field_thumbnail:alt', 'field_thumbnail_alt' ); // array matching alts to images
$this->addFieldMapping( 'field_thumbnail:title', 'field_thumbnail_title' ); // array matching titles to images
Using this same mapping, but with a single value instead of an array, it works perfectly. I added the array for multiple based on a comment in this post by BTMash -> http://www.acquia.com/comment/48941
Thanks
Comments
Comment #1
mikeryanSee also #1665334: file_link in migrate. Sorry, haven't had a chance to look at the array case yet...
Comment #2
tom.camp commentedI was able to get multiple files to migrate properly by omitting the destination_dir AND destination_file. This was documented on this page, https://drupal.org/node/1540106.
File and image fields
To migrate files directly into a file or image field, map the subfields directly.
It didn't explicitly say "do not include destination_dir or destination_file", but it was clear enough once I reread that section.
Comment #3
mikeryanWhew... Glad to hear it does work after all - I've added a note to the documentation.