--sync does not remove rows without a destination

Created on 29 October 2023, about 1 year ago
Updated 29 November 2023, about 1 year ago

Problem/Motivation

The --sync option removes migrate rows from the ID mapping and rolls back their respective destination when the row is no longer is present in the source. This is especially useful when using migrate to do an ongoing sync with an external data source.

However, the --sync option will only delete a row from the ID mapping if it has a destination. If the row was originally skipped or perhaps had an error during import, --sync will not remove it from the ID mapping.

Ultimately this leads to minor issues in bookkeeping; in my case, I want to be able to show the total number of items present in the external source and the total number of items with errors. These numbers end up being incorrect when a source row was removed before it had a destination in Drupal.

Proposed resolution

In #3260646: Rolling back a skipped row (using --sync) results in: [warning] array_flip(): Can only flip string and integer values! EntityStorageBase.php:312 β†’ , some logic was added to MigrationImportSync to prevent a PHP warning when rolling back a row without a destination. The fix here was to ultimately avoid deleting rows if they didn't have a destination.

I think this can be adjusted to more closely follow the model in core in \Drupal\migrate\MigrateExecutable::rollback that checks the truthiness of MigrateIdMapInterface::currentDestination to decide whether to rollback the destination--and will regardless delete the row from the ID mapping.

πŸ› Bug report
Status

Fixed

Version

6.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States mediabounds

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

Comments & Activities

Production build 0.71.5 2024