Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The sub_process process plugin catches MigrateSkipRowException exceptions #886

Open
github-actions bot opened this issue Oct 20, 2024 · 0 comments
Open
Labels

Comments

@github-actions
Copy link

https://www.drupal.org/node/3410921

Introduced in branch/version: 10.3.x / 10.3.0

The migration process plugin sub_process should catch MigrateSkipRowException exceptions.

For example, consider a migration like this (adapted from d7_filter_format):

source:
  plugin: d7_filter_format
process:
  filters:
    plugin: sub_process
    source: filters
    key: '@id'
    process:
      id:
        plugin: filter_id
        bypass: true
        source: name
        map:
          editor_caption: filter_caption
          editor_align: filter_align
destination:
  plugin: entity:filter_format

What happens if the filter_id process plugin throws a MigrateSkipRowException exception?

Before Drupal 10.3.0

The entire text format (filter_format entity) is skipped.

Starting with Drupal 10.3.0

Only the text filter being processed when the exception is thrown will be skipped.

Work arounds

Some migrations may have been written to rely on the bug. Such migrations can be rewritten with the help of some contributed modules.

Using Migrate Plus

The following process pipeline will check whether any rows were skipped in the sub process. If so, it will skip the current row of the main process.

dest_1:
  plugin: sub_process
  source: my_array_of_arrays
  # ...
_bc_skip:
  - plugin: multiple_values
    source:
      - my_array_of_arrays
      - '@dest_1'
  - plugin: callback
    callable: count
  - plugin: single_value
  - plugin: callback
    callable: array_unique
  - plugin: callback
    callable: count
  - plugin: skip_on_value
    method: row
    value: 2

Using Migrate Conditions

This process pipeline is similar, relying on the fact that PHP compares arrays using lengths: $array1 > $array2 if count($array1) > count($array2).

dest_1:
  plugin: sub_process
  source: my_array_of_arrays
  process:
    property:
      plugin: something_that_might_skip
      source: array_key

_bc_skip:
plugin: skip_on_condition
method: row
message: 'BC forever!'
source: my_array_of_arrays
condition:
plugin: greater_than
property: '@dest_1'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

0 participants