Throwing migration error

Created on 1 November 2023, 8 months ago

Problem/Motivation

What I am trying to achieve is look for value "office" in the array and get the phone number; because I have value "fax" so I want to store phone and fax on different field.

Hi I am using migrate_plus to run my migration; now I need a condition to filter my migration; I installed migrate_condition and added dependencies in my custom module and added following condition; while running migration I am getting following error
The "in_array" plugin does not exist. Valid plugin IDs for Drupal\migrate\Plugin\MigratePluginManager , how do I use condition migrate plugin.

  _phoneList:
      plugin: sub_process
      source: positionList
      process:
        phoneList:
          plugin: sub_process
          source: phoneList
          process:
            plugin: evaluate_condition
            condition:
              plugin: in_array
              value: office
              strict: true
            method: row
            phoneNum: phoneNum

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ’¬ Support request
Status

Fixed

Version

2.1

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada mhentry Toronto

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @mhentry
  • πŸ‡ΊπŸ‡ΈUnited States danflanagan8 St. Louis, US
  • πŸ‡ΊπŸ‡ΈUnited States danflanagan8 St. Louis, US

    The reason for the exception is that `condition` is being interpreted as a destination key in your second sub_process. So it ends up looking for a process plugin called `in_array` to process that value.

    I am a little confused about the goal here. If you post an example of the source data I might be able to offer more help.

  • πŸ‡¨πŸ‡¦Canada mhentry Toronto

    @danflanagan8, please see the attached image, sorry for privacy I hide the user information. following is my working migrate yml which gets the contact number without any condition both phone number and fax.

    _phoneList:
    plugin: sub_process
    source: positionList
    process:
    phoneList:
    plugin: sub_process
    source: phoneList
    process:
    phoneNum: phoneNum

    field_phonenum_office:
    -
    plugin: flatten
    source: '@_phoneList'

  • πŸ‡ΊπŸ‡ΈUnited States danflanagan8 St. Louis, US

    It looks like the "Office" and "Fax" flags are in the type property that is siblings with the phoneNum property. You're going to have to refer to type at some point.

    You might consider the filter_on_condition β†’ process plugin along with the has_element β†’ condition to separate the "Office" arrays from the "Fax" arrays.

    If I did this:

    _officePhoneList:
      plugin: filter_on_condition
      source: phoneList
      condition:
        plugin: has_element
        index: type
        condition: equals(Office)
    

    using your example data I would end up with

    _officePhoneList = [
      [
        phoneNume => redacted,
        extension => NULL,
        voicemailInd => TRUE,
        smsInd => FALSE,
        type => "Office"
      ]
    ]
    
  • πŸ‡¨πŸ‡¦Canada mhentry Toronto

    @ Thank you for the help, while I am trying your YAML, i am getting following error.

    The "has_element" plugin does not exist. Valid plugin IDs for Drupal\migrate\Plugin\MigratePluginManager are:" am I missing something ?

  • πŸ‡ΊπŸ‡ΈUnited States danflanagan8 St. Louis, US

    It sounds like has_element is being interpreted as a process plugin, likely because the yaml is nested within a sub_process and something isn't quite right.

  • πŸ‡¨πŸ‡¦Canada mhentry Toronto

    any suggestion would be really grateful.

  • πŸ‡ΊπŸ‡ΈUnited States danflanagan8 St. Louis, US

    I don't think I'll be able to provide any real help. It looks a little tricky. There's a sub_process inside a sub_process. That gets hard to understand.

    Sometimes if your source data is hard to work with, it is better to modify the source plugin than to use a complicated process pipeline. Or sometimes writing a single custom process plugin can be easier than trying to chain together a bunch of existing process plugins.

    Sorry I couldn't be more help. Good luck!

  • πŸ‡¨πŸ‡¦Canada mhentry Toronto

    @danflanagan8, I managed to get it work by moving the sub_process after the condition by referring this https://www.drupal.org/docs/8/api/migrate-api/migrate-process-plugins/mi... β†’

    Thanks a lot!!!

    _officePhoneList:
    plugin: sub_process
    source: positionList
    process:
    phoneList:
    -
    plugin: filter_on_condition
    source: phoneList
    condition:
    plugin: has_element
    index: type
    condition: equals(Office)
    -
    plugin: sub_process
    process:
    phoneNum: phoneNum

  • Status changed to Fixed 8 months ago
  • πŸ‡ΊπŸ‡ΈUnited States danflanagan8 St. Louis, US

    That's great news! I'll close this then. Cheers!

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024