0

I have this json.

    {
      "ProductKey": "145.1",
      "Product": {
        "Title": "Product title",
        "StartDate": null,
        "EndDate": null,    
        "ProductKeywords": [{
          "Name": "keyword 1"
        },
        {
          "Name": "keyword 2"
        },
        {
          "Name": "keyword 3"
        }],
      },
   }

So in this case I can't create a separate migration file for the taxonomy terms because the ProductKeywords is an array and have multiple taxonomy terms.

So I have done it in a single migration file with entity_generate plugin for the taxonomy term entity reference field.

keywords:
    - plugin: sub_process
      source: keyword
      process:
        value: Name
    - plugin: entity_generate
      value_key: name
      bundle_key: vid
      bundle: keyword
      entity_type: taxonomy_term
      ignore_case: true

But the taxonomy terms created with entity_generate do not gets deleted with rollback.

I know there is a postRollback migration event, where we can execute some code after rollback. But I don't know how I can know which taxonomy terms needs to be deleted on the rollback.

Is there any example or hint available?

2
  • This is not possible. If you need rollback, you must create a separate, "real" migration for your taxonomies, using a destination plugin. Then in your Products migration use migration_lookup instead of entity_generate for your taxonomies.
    – Hudri
    Dec 17, 2020 at 8:56
  • How can I use the these multiple ProductKeywords in a separate migration file for taxonomy terms. Because I need to migrate multiple taxonomy terms from a single json object.
    – Ahmad
    Dec 17, 2020 at 9:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.