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.

Comments

mediabounds created an issue. See original summary.

mediabounds’s picture

Status: Active » Needs review
StatusFileSize
new1.63 KB

The attach patch will always remove rows from the ID mapping but will only call rollback on the destination if the row had a destination; this is consistent with how core works during rollback.

heddn’s picture

Status: Needs review » Reviewed & tested by the community
heddn’s picture

Thanks for your contributions.

  • heddn committed 752a246a on 6.0.x authored by mediabounds
    Issue #3397550 by mediabounds, heddn: --sync does not remove rows...
heddn’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.