Score:1

Migrate CSV to content type with paragraphs

de flag

I'm trying to import a CSV File into Content Types and Paragraphs, using Migrate module (and mainly this tutorial : https://mtech-llc.com/blog/charlotte-leon/migration-csv-data-paragraphs).

For this I have created a custom module in modules/custom, and I added the .yml files in config/install.

Here's my two .yml (produit_epargne is for the Content Type, and epargne_support is for the Paragraph) :

dependencies:
  enforced:
    module:
      - produit_migration
id: produit_epargne
migration_group: produit_group
source:
  plugin: csv
  path: public://csv/test_import_csv_migrate.csv
  ids: 
    [id]
  header_row_count: 1
  delimiter: ';'
  fields:
    - 
      name: id
      label: id
    - 
      name: title
      label: title
    -
      name: field_referent
      label: field_referent
    -
      name: field_fiches_gamme
      label: field_fiches_gamme
    -
      name: field_date_mise_a_jour
      label: field_date_mise_a_jour
process:
  title: title
  field_referent: field_referent
  field_fiches_gamme: field_fiches_gamme
  field_date_mise_a_jour: 
    plugin: format_date
    from_format: Y-m-d
    to_format: Y-m-d
    source: field_date_mise_a_jour
    field_supports/target_id:
      -
        plugin: migration_lookup
        migration: epargne_supports
        no_stub: true
        source: id
      -
        plugin: extract
        index:
          - '0'
    field_supports/target_revision_id:
      -
        plugin: migration_lookup
        migration: epargne_supports
        no_stub: true
        source: id
      -
        plugin: extract
        index:
          - 1
destination:
  plugin: 'entity:node'
  default_bundle: produit_epargne
migration_dependencies:
  required: 
    - epargne_support
  optional: { }
dependencies:
  enforced:
    module:
      - produit_migration
id: epargne_support
migration_group: produit_group
source:
  plugin: csv
  path: public://csv/test_import_csv_migrate.csv
  header_row_count: 1
  delimiter: ';'
  ids: 
    [id]
  fields:
    -
      name: id
      label: id
    - 
      name: field_nb_fonds_euros
      label: field_nb_fonds_euros
    - 
      name: field_nb_fonds_thematiques
      label: field_nb_fonds_thematiques
    - 
      name: field_nb_support_fcpe
      label: field_nb_support_fcpe
    - 
      name: field_nb_support_uc
      label: field_nb_support_uc
process:
  field_nb_fonds_euros: field_nb_fonds_euros
  field_nb_fonds_thematiques: field_nb_fonds_thematiques
  field_nb_support_fcpe: field_nb_support_fcpe
  field_nb_support_uc: field_nb_support_uc
destination:
  plugin: 'entity_reference_revisions:paragraph'
  default_bundle: epargne_supports
migration_dependencies:
  required:
    - files
  optional: { }

But I have two major issues :

  1. First, the migration group produit_group is not recognized when I run : drush migrate:imports --group produit_group which is probably the source of the second issue
  2. Second, when I run drush migrate:imports produit_epargne, it only creates the content types withtout the paragraphs linked to it.

Does anybody see the problem in my code / configuration ?

Lambic avatar
ph flag
This is an alternative approach: https://drupal.stackexchange.com/questions/278476/paragraphs-from-sub-process/278477#278477
miststudent2011 avatar
fr flag
Does this help ? https://drupal.stackexchange.com/questions/299395/migrate-paragraphs-from-csv-file
miststudent2011 avatar
fr flag
The command is wrong . It should be be `drush migrate:imports --group=produit_group`
CanardPpc avatar
de flag
Thanks for your response, unfortunately I still have the same issues. The command does not change the problem either.
Score:0
us flag

Here are my thoughts for your code. Hope it helps!

#1 It should be drush migrate:import --group=produit_group instead of drush migrate:imports --group produit_group

#2 The paragraph migration name is wrong in the below mapping. It should be epargne_support instead of epargne_support

field_supports/target_id:
      -
        plugin: migration_lookup
        migration: epargne_supports
        no_stub: true
        source: id
      -
        plugin: extract
        index:
          - '0'
    field_supports/target_revision_id:
      -
        plugin: migration_lookup
        migration: epargne_supports
        no_stub: true
        source: id
      -
        plugin: extract
        index:
          - 1
CanardPpc avatar
de flag
Thanks for your response. Indeed I have misspelled my migrations name here, but I still have the same issues. No matter which command I use to run migrations group, I got this error : *You must declare "ids" as a unique array of fields in your source settings.*. In my understanding, it may say that no migration group of this name was find.
Pushpinder Rana avatar
us flag
This error looks similar to this one - https://drupal.stackexchange.com/questions/297975/you-must-declare-ids-as-a-unique-array-of-fields-in-your-source-settings
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.