6

I am trying to migrate a Drupal 7 site to a Drupal 8 site. I already created my module for migration and I have a content type that has a title, field_picture and a field_text in Drupal 7.

I want to migrate it to Drupal 8 where field_text = field_description and field_picture is field_image.

I tried the following:

id: drupal7_fruit
label: "Test migration"
migration_group: drupal7
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_text
  field_image:
    plugin: iterator
    source: field_picture
    process:
      target_id: fid
      alt: alt
      title: title
      width: width
      height: height
destination:
  plugin: 'entity:node'
  default_bundle: fruit
migration_dependencies: {}

I could migrate description and title, but the image is never migrated.

What am I doing wrong?

EDIT

migrate_plus.migration.drupal7_fruit.yml

    id: drupal7_fruit
label: "Migrate Fruit Content Type"
migration_group: drupal7
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_descricao: field_body
destination:
  plugin: 'entity:node'
  default_bundle: fruit
  migration_dependencies:
    optional: drupal7_image

migrate_plus.migration.drupal7_image.yml

 id: drupal7_image
label: Images
migration_tags:
  - Drupal 7
source:
  plugin: d7_file
  constants:
    source_base_path: ''
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

Edited my question because @Berdir in the comments said that images or files must have a different migration file but still can't migrate images. I restored my D8 site database to start all from scratch.

8

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!

| improve this answer | |
5

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.

| improve this answer | |
  • Thank you Berdir for your explanation, I will try and thanks for the Content advice. Where can I find that template? (I am not with access to the computer in the moment) thanks – Henrique Alho Mar 25 '17 at 0:31
  • Same way as all migration templates, in the migration_templates folder of the module that provides it: api.drupal.org/api/drupal/… – Berdir Mar 25 '17 at 20:52
  • Hi Berdir, I changed my file and created another file for migration of images but still can't migrate content with images, just description and title. I updated my question – Henrique Alho Mar 27 '17 at 9:12

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.