Migration process plugin input and output

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
chx's picture

Migration process plugin input and output

Edit: 8f95381 implements 1, this is done.

Currently the migration process plugin always emits a list of destination ids. If you want a single id you need to run the extract plugin:

  roles:
    -
      plugin: migration
      migration: d6_user_role
      source: roles
    -
      plugin: extract
      index:
        - 0

The roles source is a list of D6 role ids. Because it's a list and not a scalar, MigrateExecutable::processRow will iterate over it and feed every role id one by one to the migration process plugin. The output is array(d8_role_name) so we need to run extract to arrive to d8_role_name.

Although in an ideal world the plugin would only accept a list of source ids and emit a list of destination ids for the sake of the simple multiple handling, it is already accepting a scalar for a source id. However, as seen above it always answers with a list of destination ids. This assymetry is galling and confusing. There are two ways to restore symmetry:

  1. When the migration process receives a scalar source id the output will be a scalar destination id (and throw an exception if there is more than destination id)
  2. Add a wrap plugin, the counterpart of extract. Make the migration process plugin consistent and only accept an array of source ids. There's nothing else that would accept a scalar for source id values.

Both has pros and cons: 1. makes the migration configuration entity simpler but it makes source and destination ids inconsistent across the codebase. For those who only write the YAML this might not be that big of a problem but how many people will ever only write the YAML? When writing tests, it's a good idea to assert the correctness of the idmap for example. 2. makes the migration configuration entity longer to write for sure but it keeps source and destination ids consistently a list of ids.

Comments

Not a strong opinion on that,

penyaskito's picture

Not a strong opinion on that, but I would chose 1), based on that I think that there could be more people writing only YAML migrations than we could think.

--
Christian López Espínola (@penyaskito)

Seems that 1) it's more

claudiu.cristea's picture

Seems that 1) it's more intuitive for a newcomer and for most of migrations, even if scalar is the exception of list. I would go with 1)

________________
Claudiu Cristea
webikon.com

Right now both the D7 and D8

benjy's picture

Right now both the D7 and D8 migrate modules have always worked with an array of source and destination ids. Personally, I don't like the idea of the Id's been a scalar sometimes and array others. We would probably lose things like type hinting in some places eg, lookupDestinationId(array $source_id_values);

On the other hand, having to do a wrap and then an extract when you're working with scalar values does seem a bit clumsy but kind of makes sense when you have the mindset that src and dest ids should always be an array.