Issue Summary
skip_on_empty's interaction with array sources that are considered 'multiple' values is poorly documented, and can be unintuitive.
Proposed resolution
Add documentation to the top of the plugin, that explicitly describes the expected behavior of skip_on_empty when dealing with multiple value sources, including when the source array contains 0 elements.
Original issue summary
I have been scratching my head over this issue. The source sometimes has a blank offers, sometimes it is an array with data and sometimes it is an empty array - like this one:
https://api.hel.fi/linkedevents/v1/event/matko:16134/
With the latter example I was getting a bunch of Array index missing, extraction failed exceptions from the extract plugin, despite the skip_on_empty
plugin running before, as you can see from my yml file:
field_offers_is_free:
-
plugin: skip_on_empty
method: process
source: offers
-
plugin: extract
index:
- 0
- is_free
field_offers_info_url:
-
plugin: skip_on_empty
method: process
source: offers
-
plugin: extract
default: false
index:
- 0
- info_url
- fi
I managed - in the end - to track down the reason for why our skip_on_empty plugin was never called: When Get sets $multiple
to true, processRow in MigrateExecutable runs a foreach on the value - causing the whole skip_on_empty plugin to be skipped.
With this quick fix in modules/migrate/src/Plugin/migrate/process/Get.php
's transform function things work fine for me:
if (is_string($source)) {
$a = is_array($return[0]);
$b = !empty($return[0]);
$this->multiple = $a && $b;
return $return[0];
}
Did I encounter a bug in Migrate or should I change my migration configuration?