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.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3397550-2-remove-unsynced-source-rows.patch | 1.63 KB | mediabounds |
Comments
Comment #2
mediabounds commentedThe 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.
Comment #3
heddnComment #4
heddnThanks for your contributions.
Comment #6
heddn