Drupal - Migrating images and files
Thank you for Berdir's help but I noticed that I was missing some information on my drupal7_fruit migration file like the values for field_image and migration dependencies.
The working solution:
migrate_plus.migration.drupal7_image.yml
id: drupal7_image
label: Images
migration_group: drupal7
migration_tags:
- Drupal 7
source:
plugin: d7_file
constants:
source_base_path: '/var/www/username/drupal7/' # Full location of your drupal7 site
process:
fid: fid
filename: filename
source_full_path:
-
plugin: concat
delimiter: /
source:
- constants/source_base_path
- filepath
-
plugin: urlencode
uri:
plugin: file_copy
source:
- '@source_full_path'
- uri
filemime: filemime
status: status
created: timestamp
changed: timestamp
uid: uid
destination:
plugin: entity:file
migration_dependencies: {}
migration_plus.migration.drupal7_fruit.yml
id: drupal7_fruta
label: "Migrate Fruit Content Type"
migration_group: drupal7
migration_tags:
- Drupal 7
source:
plugin: d7_node
node_type: fruit
process:
nid: nid
vid: vid
langcode:
plugin: default_value
source: language
default_value: und
title: title
uid: node_uid
status: status
created: created
changed: changed
promote: promote
sticky: sticky
revision_uid: revision_uid
revision_log: log
revision_timestamp: timestamp
field_description: field_body
field_image: # Image field name in Drupal 8 site
plugin: iterator
source: field_photo # Image field name in Drupal 7 site
process:
target_id: fid
alt: alt
title: title
width: width
height: height
destination:
plugin: 'entity:node'
default_bundle: fruit
migration_dependencies:
required:
- drupal7_image
Hope this may help anyone with the same problem in the future!
images and files are their own entity type. The node table just contains the file id, basically an entity reference.
You need a separate file migration that you need to execute first. You can create it based on the d7_file migration template.
Note: If you migrate the existing nid and vid (and fid), you need to be certain that you have no existing data with conflicting ids on your D8 site or you will get conflicts. You can leave those out then it will automatically use auto incrementing ids just like when you create content manually. But then you need to set up a migration process plugin to map the old to the new file id.