Score:0

How do I insert migrated file info into a file field?

gb flag

Successfully migrated public and private files to D9 system using core d7_file and d7_file_private migrations.

Now trying to migrate the file info into file fields (entity_reference_revisions:paragraph migration). My source plugin is generating the source fields, but nothing is being migrated to the file fields and there are no messages. All other fields are migrating successfully.

These are the two file fields in the paragraph entity into which I am trying to insert file info:

  • field_private_files (file field)
  • field_public_files (file field)

My source plugin (d7_agenda_section):

  • does a migrate_lookup and gets the migrated file fids for this paragraph
  • does a lookup in the source database and gets the source file description for each fid
  • creates (using prepareRow()) both a private and public field each of which contains the file target_id and description in the following array format:
(
    [0] => Array
        (
            [target_id] => 325
            [description] => 3.C. Employment Chart (v4)
        )

    [1] => Array
        (
            [target_id] => 339
            [description] => 5.A. Nurse School Board Report
        )

    [2] => Array
        (
            [target_id] => 340
            [description] => 5.B. Board Calendar
        )

)

This is my migration code:

source:
  plugin: d7_agenda_section
  key: migrate
  langcode: en
process:
  'field_content/value': body_value
  'field_content/format': body_format
  field_private_files:
    -  plugin: skip_on_empty 
       method: process
       source: private
    -  plugin: sub_process
       process:
         target_id: target_id
         display: 
           plugin: default_value
           default_value: 1
         description: description
  field_public_files:
    -  plugin: skip_on_empty 
       method: process
       source: public
    -  plugin: sub_process
       process:
         target_id: target_id
         display: 
           plugin: default_value
           default_value: 1
         description: description
destination:
  plugin: entity_reference_revisions:paragraph
  default_bundle: agenda_section
    migration_dependencies:
    required: 
    -  sbn_migrations_d7_file
    -  sbn_migrations_d7_file_private

I run the migration and the field_content is migrated, but nothing in field_public_files or field_private_files.

I am thinking my problem is with the skip_on_empty usage as I have used similar array field processing code successfully to migrate nested paragraphs:

  field_body1:
    source: prepare_multiple_paragraphs
    plugin: sub_process
    process:
      target_id: target_id
      target_revision_id: target_revision_id

See sample code: https://atendesigngroup.com/articles/drupal-8-migration-multiple-paragra...

Some paragraphs will have public and private files, some will have none, others will have one or the other. I have read that there are problems with the sub_process plugin if the array is empty. So my goal here is to skip the field if it contains an empty array.

Looking for suggestions on how to resolve this.

Score:0
gb flag

First, I made a code mistake. My source plugin generated fields are public_files and private_files (not public and private).

Next, I just took out the skip_on_empty completely. I am not quite sure yet what happens when a paragraph has no files, but for right now, migrated file data is being imported into the file field correctly:

process:
  'field_content/value': body_value
  'field_content/format': body_format
  field_private_files:
    source: private_files
    plugin: sub_process
    process:
      target_id: target_id
      display: display
      description: description
  field_public_files:
    source: public_files
    plugin: sub_process
    process:
      target_id: target_id
      display: display
      description: description
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.