0

I am migrating content from Drupal 7 to Drupal 8. There is an audio field that I am currently moving to media via a custom process during migration.

When I get the id of the new media created I can't seem to get it to attach to my new media reference field in the also newly created node.

Can anyone tell me what is wrong with the import below?

field_audio_fileinfo:
-
  plugin: sub_process
  source: field_audio_fileinfo
  process:
    target_id:
      -
        plugin: migration_lookup
        method: process
        source: fid
        migration: upgrade_d7_file
      -
        plugin: my_custom_process
        destination: field_media_audio

In my custom process I can save the media and get it's ID via:

$media_id = $audio_media->id();
$arr[] = array(
  'target_id' => $media_id,
  'display' => NULL,
  'description' => NULL
);
return $arr;

But it doesn't seem to populate the destination field.

This is also the case if I just return the ID directly from the process.

0

When I have done a similar type of migration at that time I did the following steps:

  • First I created media type Audio in Drupal 8 and it's fields.

  • Then I exported all audio file details and FID from D7 and created csv file.

  • Written migration script to import audio into media.

Example:

source:
  plugin: csv
  path: 'csv file path'
  header_row_count: 1
  keys:
    - fid
  type: audio
  constants:
    bundle: audio
process:
  mid: fid
  bundle: constants/bundle
  langcode:
    plugin: default_value
    source: language
    default_value: und
  name: filename
  uid: uid
  created: upload_date
  changed: upload_date
  field_media_audio_file/target_id: fid
destination:
  plugin: 'entity:media'
  migration_dependencies: {  }
migration_dependencies: null
  • The same csv I used to import data into file entity and written migration script.

Example:

source:
  plugin: csv
  path: 'csv file path'
  header_row_count: 1
  keys:
    - fid
process:
  uid: uid
  fid: fid
  filename: filename
  created: upload_date
  changed: upload_date
  filemime: mime
  uri: uri
destination:
  plugin: 'entity:file'
  source_path_property: filepath
  destination_path_property: uri
migration_dependencies: {  }
  • After that, I attached the FID to my node field.
process:
  field_audio/target_id: fid

I am keeping media id, FID of Drupal 8 same as FID of Drupal 7. So we can attach the same FID to the node directly.

0

There was a fault with my migration yaml.

The destination field in Drupal 8 was field_media_audio but as you can see in the question I had it trying to save to field_audio_fileinfo which was the Drupal 7 source. Silly me.

Once I realised and corrected the destination it all worked and now media is created and referenced in the one pass of my migration script.

  field_media_audio:
-
  plugin: sub_process
  source: field_audio_fileinfo
  destination: field_media_audio
  process:
    target_id:
      -
        plugin: migration_lookup
        method: process
        source: fid
        migration: upgrade_d7_file
      -
        plugin: my_custom_process

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.