Allow process plugins to declare themselves final

Created on 26 October 2021, over 3 years ago
Updated 7 June 2023, about 2 years ago

Problem/Motivation

The MigrateSkipProcessException causes the processed value is set to NULL, no more plugins are used and the the value is not migrated.
See \Drupal\migrate\MigrateExecutable::processRow

In some cases, we want to skip the process (it means to escape from the chain of process plugins), but keep the current value and migrate the current value.

Proposed resolution

Create a way for a process plugin to declare itself as final, which will prevent additional process plugins from running for that pipeline. This both solves the original problem, (by allowing a plugin to return the original value and declaring itself final) AND provides us a path towards removing the ugly Exception-As-A-Signal which is MigrateSkipProcessException (by having the plugin return null or void and declaring itself as final)

Example:

-
  plugin: entity_lookup
-
  plugin: log
-
  # All, not null values end here and are migrated.
  plugin: continue_if_null
-
  # This plugin is processed only if the value from above is NULL.
  plugin: migration_lookup
  source: alternative_value
class ContinueIfNull extends ProcessPluginBase {

  /**
   * Continue if the value is NULL.
   *
   * @throws \Drupal\migrate\MigrateSkipProcessException
   */
  public function transform($value, ...) {
    if (!is_null($value)) {
      throw new MigrateSkipProcessException(NULL, TRUE);
    }
    return NULL;
  }

The alternative way is to use a new exception, like MigrateFinalProcessException, but I chose the way described above.

✨ Feature request
Status

Needs work

Version

11.0 πŸ”₯

Component
MigrationΒ  β†’

Last updated about 4 hours ago

Created by

πŸ‡¨πŸ‡ΏCzech Republic martin_klima

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024