Allow process plugins to stop further processing on a pipeline

Created on 26 October 2021, over 2 years ago
Updated 1 February 2024, 5 months 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.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

✨ Feature request
Status

Fixed

Version

11.0 🔥

Component
Migration  →

Last updated about 2 hours ago

Created by

🇨🇿Czech Republic martin_klima

Live updates comments and jobs are added and updated live.
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.69.0 2024