On this page
File migration
The simplest and most efficient way to get your files imported is to use the distinct file migration class, rather than try to map them directly in the referencing classes. These classes basically map the source files (or file_managed) table to the destination file_managed table, copying referenced files as necessary. The supported arguments:
- user_migration: The machine name of your user migration, used to properly assign ownership of the files.
- default_uid: A default destination uid to use as the default owner of files where a legacy owner isn't identified (for example, files owned by the account with uid 1 in the legacy system, since that account is not migrated).
- source_dir: The source destination from which to copy migrated files. See here for more info.
- destination_dir: The destination to which to copy migrated files. This defaults to public://.
- file_class: An override for the default MigrateFileUri class - you would use this if you had extended that class with application-specific behavior.
$api['migrations']['ExampleFile'] = $common_arguments + array(
'class_name' => 'DrupalFile6Migration',
'description' => t('Import Drupal 6 files'),
'user_migration' => 'ExampleUser',
'default_uid' => 1,
'source_dir' => 'http://example.com',
'destination_dir' => 'public://legacy_files',
);
Using this strategy, files are migrated before being used in a subsequent migration, such as for a node containing a referenced image field. In the (custom) node migration, the referenced file should be migrated with a field mapping specifying a file_class of MigrateFileFid. This migrates only the reference to the file, not the file itself. Additionally, preserve_files should be set to TRUE to avoid deleting the actual file, should the node migration be rolled back (requires Migrate 7.x-2.6 or later). The mapping in the constructor for the node migration might contain:
$this->addFieldMapping('field_my_image', 'field_my_source_image')
->sourceMigration('MyFileMigrationMachineName');
$this->addFieldMapping('field_my_image:file_class')
->defaultValue('MigrateFileFid');
$this->addFieldMapping('field_my_image:preserve_files')
->defaultValue(TRUE);
$this->addFieldMapping('field_my_image:title', 'image_copyright')
->defaultValue(t('(c) 2012 My Site'));
$this->addFieldMapping('field_my_image:alt', 'image_description')
->defaultValue('');
$this->addFieldMapping('field_my_image:language')
->defaultValue(LANGUAGE_NONE);
In the UI
In Migrate 7.x-2.6 or later, one will need to edit the classes after running the UI migration wizard. Each content type or entity will need to be manually set. The destination file field needs to be mapped from the source file field, with the source migration set to the file migration that was automatically created (after agreeing to it in the wizard). And, the file_class subfield "Implementation of MigrateFile to use" needs to have a default value of MigrateFileFid (no source field mapped). It may also be useful to give a default value of TRUE to the field "Option: Boolean indicating whether files should be preserved or deleted on rollback".
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion