1

From the continuation of this question I am trying to import paragraphs into my site using migrate from source csv.

I have a single CSV file where there are various fields from those fields I would like to import three fields into paragraph fields, for this process I have created a paragraph type called as fup_balance and it has three fields called as field_upload , field_download and field_total which are of type textfield . Paragraph has limit of one value.

I have written a custom yml for the paragraph migration and included it as dependency in node migration yml but the data is not being imported and paragraph is empty after import.

Can anyone please point out why it is failing to import paragraphs ?

I have referenced this example for creating yml .

My node and paragraph import ymls as follows :

migration_examples/migrations/article_csv_import.yml

id: article_csv_import
label: Import Articles
migration_group: default
migration_tags:
  - Article CSV Migration

source:
  plugin: 'csv'
  # Full path to the file.
  path: public://subscription-list-small-copy.csv
  # Column delimiter. Comma (,) by default.
  delimiter: ','
  enclosure: '"'
  header_offset: 0
  ids:
    - id
  fields:
    0:
      name: id
      label: 'Id'
    1:
      name: title
      label: 'Title'
    2:
      name: body
      label: 'Post body'
    3:
      name: field_activation_date
      label: 'Activation Date'
    4:
      name: field_expiry_date
      label: 'Expiry Date'
    5:
      name: field_upload
      label: 'FUP Balance Upload'
    6:
      name: field_download
      label: 'FUP Balance Download'
    7:
      name: field_total
      label: 'FUP Balance Total'
process:
  title: title
  body: body
  #activation date of the account.
  field_activation_date:
    -
      plugin: format_date
      from_format: Y-m-d H:i:s
      to_format: 'Y-m-d\TH:i:s'
      from_timezone: 'America/Managua'
      to_timezone: 'UTC'
      source: field_activation_date
  # expiry date of the account.
  field_expiry_date:
    -
      plugin: format_date
      from_format: Y-m-d H:i:s
      to_format: 'Y-m-d\TH:i:s'
      from_timezone: 'America/Managua'
      to_timezone: 'UTC'
      source: field_expiry_date
  # paragraph field.      
  field_fup_details:
    -
      plugin: sub_process
      source: field_fup_details
      process:
        target_id:
          -
            plugin: migration_lookup
            migration: fup_balance_csv_import
            source: value
            no_stub: TRUE
          -
            plugin: extract
            index:
              - 0
        target_revision_id: '@target_id'
  type:
    plugin: default_value
    default_value: article

destination:
  plugin: entity:node

migration_dependencies:
  required:
    - fup_balance_csv_import
  optional: { }

migration_examples/migrations/fup_balance_csv_import.yml

id: fup_balance_csv_import
label: FUP details from CSV
migration_group: default
migration_tags:
  - FUP details CSV Migration

source:
  plugin: 'csv'
  # Full path to the file.
  path: public://subscription-list-small-copy.csv
  # Column delimiter. Comma (,) by default.
  delimiter: ','
  # Field enclosure. Double quotation marks (") by default.
  enclosure: '"'
  # The row to be used as the CSV header (indexed from 0),
  # or null if there is no header row.
  header_offset: 0
  # The column(s) to use as a key. Each column specified will
  # create an index in the migration table and too many columns
  # may throw an index size error.

  ids:
    - id
  fields:
    0:
      name: id
      label: 'Id'
    1:
      name: title
      label: 'Title'
    2:
      name: body
      label: 'Post body'
    3:
      name: field_activation_date
      label: 'Activation Date'
    4:
      name: field_expiry_date
      label: 'Expiry Date'
    5:
      name: field_upload
      label: 'FUP Balance Upload'
    6:
      name: field_download
      label: 'FUP Balance Download'
    7:
      name: field_total
      label: 'FUP Balance Total'

process:
  field_upload: field_upload
  field_download: field_download
  field_total: field_total

destination:
  plugin: entity_reference_revisions:paragraph
  default_bundle: fup_balance

migration_dependencies:
  required: {}
  optional: {}

Sample CSV Data : subscription-list-small-copy.csv

id,title,body,field_activation_date,field_expiry_date,field_upload,field_download,field_total
1,Title 1,Body 1,2012-12-22 2:36:03,2013-01-03 0:00:00,NA,NA,"DATA: NA, TIME: NA"
2,Title 2,Body 2,2013-08-16 0:00:00,2013-09-15 0:00:00,NA,NA,"DATA: NA, TIME: NA"
3,Title 3,Body 3,2013-09-14 0:00:00,2013-10-14 0:00:00,NA,NA,"DATA: NA, TIME: NA"
4,Title 4,Body 4,2014-04-08 0:00:00,2014-04-07 23:59:59,NA,NA,"DATA: NA, TIME: NA"
5,Title 5,Body 5,2014-09-30 0:00:00,2015-03-29 11:00:00,NA,35840.0 MB,"DATA: 35840.0 MB, TIME: NA"
6,Title 6,Body 6,2014-12-09 12:29:00,2015-01-09 12:29:00,NA,40960.0 MB,"DATA: 40960.0 MB, TIME: NA"
7,Title 7,Body 7,2014-12-31 11:08:00,2015-06-26 23:59:59,NA,61440.0 MB,"DATA: 61440.0 MB, TIME: NA"
8,Title 8,Body 8,2015-02-25 19:12:00,2015-08-10 23:59:59,NA,35840.0 MB,"DATA: 35840.0 MB, TIME: NA"
9,Title 9,Body 9,2015-03-01 11:19:00,2015-02-28 23:59:59,NA,35840.0 MB,"DATA: 35840.0 MB, TIME: NA"
10,Title 10,Body 10,2015-03-02 18:01:00,2015-08-20 23:59:59,NA,30720.0 MB,"DATA: 30720.0 MB, TIME: NA"

2 Answers 2

1

Don't set target_id and target_revision_id to the same value, those are two completely different things: The "id" is constant for the paragraph's lifetime, the "revision_id" will change every time you update your host node.

Try something like this in your node migration:

field_fup_details:
  plugin: sub_process
  source: field_fup_details
  process:
    temp_paragraph_keys:
      plugin: migration_lookup
      migration: fup_balance_csv_import
      source: value
      no_stub: TRUE
    target_id:
      plugin: extract
      source: '@temp_paragraph_keys'
      index:
        - 0
    target_revision_id:
      plugin: extract
      source: '@temp_paragraph_keys'
      index:
        - 1
2
  • Thank you for the answer but still same issue. Changed as per your suggestion still data is not imported. del.dog/precywafel.txt Commented Jan 13, 2021 at 9:57
  • what should the key source: field_fup_details , refer to does it refer to paragraph referenced field key or some other ? In my case is field_fup_details is paragraph field key Commented Jan 13, 2021 at 9:58
1

So after further debugging I am able to finally import the paragraph data.

For any one who want to debug whether the paragraph data is being imported or not , create the view for the paragraph items so that you can check imported data as paragraphs doesn't have native way to check the data . Thanks to tip fro here

An also some times you might get unmet dependencies errors while importing the paragraphs. In order to solve that mention dependencies as optional dependencies and import the dependencies first manually by using the the migration import command and then import the parent entities.

And coming to the actual answer how I defined my paragraph fields refer below:

 pseudo_field_fup_details:
    plugin: migration_lookup
    migration: fup_balance_csv_import
    source: id  # Unique reference id.
  field_fup_details:
    plugin: sub_process
    source:
      - '@pseudo_field_fup_details'
    process:
      target_id: '0'
      target_revision_id: '1'

If anyone got any inputs for the approach please suggest.

2
  • Added more details here drupal.stackexchange.com/a/299616 Commented Jan 21, 2021 at 6:26
  • You don't really need a pseudo field in this case. You can just chain the migration_lookup process followed with sub_process on the same field_fup_details field.
    – Beebee
    Commented Mar 15, 2022 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.