Problem/Motivation
If a destination plugin sets NULL values as part of an id, then we get an error on rollback.
Steps to reproduce
Custom migrate destination plugin with a multiple-value id.
E.g. "a", "b", "c".
Let the destination id contain NULL for some records: E.g. ['A', 'B', NULL].
Create a migration with this destination plugin, with at least one record where the destination id will have a NULL value.
Run the import.
Run the rollback.
We see error messages like this:
Undefined array key "c" Sql.php:597
Technical explanation
The MigrateExecutable::rollback() gets a destination key from $id_map->currentDestination();
It then passes this key to $id_map->deleteDestination(..), which calls ->lookupSourceId() on the Sql id map.
The Drupal\migrate\Plugin\migrate\id_map\Sql::currentDestination() removes NULL values from the destination ids record.
The Drupal\migrate\Plugin\migrate\id_map\Sql::lookupSourceId(..) and also ::deleteDestination(..) expect all values to be present.
Proposed resolution
I see two options:
1. Have Sql::currentDestination() not remove NULL values.
2. Let Sql::lookupSourceId(..) and also Sql::deleteDestination(..) assume NULL if an array key is not present.
In both cases, Sql::lookupSourceId(..) and Sql::deleteDestination(..) need to add an "IS NULL" filter in the query condition.
foreach ($this->destinationIdFields() as $field_name => $destination_id) {
if (!isset($destination_id_values[$field_name])) {
$query->isNull("map.$destination_id");
}
else {
$query->condition("map.$destination_id", $destination_id_values[$field_name], '=');
}
}
This
Merge request link
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet