1

I'm trying on this for two days now and I don't get it. I need some more experienced people to look over my code. This is my first Drupal 8 project, meaning, Drupal 8, Twig, Migration API, Yaml... it's a lot of new stuff for me and I'm still learning.

I need to import data from a XML file. I wrote a custom module and was able to migrate all the XML nodes into D8 nodes, but only text fields and taxonomy terms.

There are also image references in some XML nodes and I know, I have to migrate them first into file entities before referencing them in the nodes. So I wrote a second migrate configuration, but it doesn't work and I'm stranded. I don't find a mistake in my yml file, it's close to this example on GitHub: drupal-migration-example

My source data folder, containing some jpgs and a XML file, is stored inside the public file folder.

Maybe important for my issue: Not every XML node has an image reference. But I think I catch that with plugin: skip_row_if_not_set. I don't know how to debug that.

What I have so far:

id: clio_cover_import
label: Clio-Cover-Import
migration_group: werk_import
# Source
source:
  # XML data parser
  plugin: url
  data_fetcher_plugin: http
  data_parser_plugin: xml
  urls: public://import/werk-import.xml
  item_selector: /Werke/Werk
  fields:
    -
      name: clio_cover
      label: 'Werk-Cover'
      selector: Coverpath
  ids:
    clio_cover:
      type: string
  constants:
    file_source_uri: public://import
    file_dest_uri: 'public://cover_uploads'
# Destination
destination:
  plugin: 'entity:file'
#Mappings
process:
  settings:
     # Check if the "clio_cover" key exists in the "data" array.
     plugin: skip_row_if_not_set
     index: clio_cover
     source: data
     message: "Missed the 'data' key"
  file_source:
    -
      plugin: concat
      delimiter: /
      source:
        - constants/file_source_uri
        - clio_cover
    -
      plugin: urlencode
  file_dest:
    -
      plugin: concat
      delimiter: /
      source:
        - constants/file_dest_uri
        - clio_cover
    -
      plugin: urlencode
  uid:
    plugin: default_value
    default_value: '1'
  filemime:
    plugin: default_value
    default_value: 'image/jpeg'
  status:
    plugin: default_value
    default_value: '1'
  filename: clio_cover
  uri:
    plugin: file_copy
    source:
      - '@file_source'
      - '@file_dest'
# Dependencies
dependencies:
  enforced:
    module:
      - clio_import_modul
migration_dependencies:
  required: {}
  optional: {}

Every help is very appreciated!

1

Thanks to quietone, I figured it out. The settings for skipping row didn't work as expected. Instead of repairing, it's much easier for me to modify the XML-file and remove all rows without image node.

So I don't need the skipping plugin anymore and can change the process part to this (and it's working):

process:
  file_source:
  -
    plugin: concat
    delimiter: /
    source:
      - constants/file_source_uri
      - clio_cover
  file_dest:
    -
      plugin: concat
      delimiter: /
      source:
        - constants/file_dest_uri
        - clio_cover
  uid:
    plugin: default_value
    default_value: '1'
  uri:
    plugin: file_copy
    source:
      - '@file_source'
      - '@file_dest'
  filename: clio_cover_name
0

Things to check are the migrate tables, migrate_map_clio_cover_import and migrate_message_clio_cover_import. The latter table can be seen with drush mmsg clio_cover_import. The message table will have a message for every row skipped which may determine if the skip on the settings property is working as you expect.

Also, check the file_managed table.

Apologies if you've done these already.

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.