Using "/" item_selector in Json parser plugin config does not work as expected anymore

Created on 4 August 2024, 2 months ago
Updated 6 September 2024, about 1 month ago

Problem/Motivation

The 6.0.3 release introduced a change in the JSON parser plugin API which made my migrations to report zero rows. With Migrate Plus "> 6.0.3", using a / item selector was valid. But now, both in 6.0.3, 6.0.4 (and also in dev) it is evaluated as an invalid item selector.
This is source plugin configuration:

  plugin: url
  data_fetcher_plugin: file
  item_selector: "/"
  data_parser_plugin: json
  urls: [...]
  ids: [...]
  fields: [...]

In 6.0.2 and before, in the parser plugin, the logic in regards of the item selector was this:

// Otherwise, we're using xpath-like selectors.
$selectors = explode('/', trim((string) $this->itemSelector, '/'));
foreach ($selectors as $selector) {
  if (is_array($source_data) && array_key_exists($selector, $source_data)) {
    $source_data = $source_data[$selector];
  }
}
return $source_data;

Right now, it is a bit different, and this is the change which makes my migration to fail:

// If the item_selector is an empty string, return all.
if ($item_selector === '') {
  return $this->sourceData;
}

// Otherwise, we're using xpath-like selectors.
$selectors = explode('/', trim($item_selector, '/'));
$return = $this->sourceData;
foreach ($selectors as $selector) {
  // If the item_selector is missing, return an empty array.
  if (!isset($return[$selector])) {
    return [];
  }
  $return = $return[$selector];
}
return $return;

Proposed resolution

  1. Restore BC in regards of the previously accepted (and processed) item_selector configuration...
  2. ...but, log a warning about they are deprecated from 6.0.3 (or 6.0.5 ?)

Remaining tasks

  1. Decide whether using only slash is acceptable or not. (The MR I will create accepts it.)
  2. Decide whether the support of broken / invalid selectors is really deprecated or not. (I assume these selectors are deprecated.)

User interface changes

Nothing.

API changes

BC restored as in 6.0.2; but broken selectors are deprecated.

Data model changes

πŸ› Bug report
Status

Needs review

Version

6.0

Component

Plugins

Created by

πŸ‡­πŸ‡ΊHungary huzooka Hungary πŸ‡­πŸ‡ΊπŸ‡ͺπŸ‡Ί

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024