Problem/Motivation

I have set up a migration in 2 steps:
* first migrate data from Drupal 6 into a paragraph entity_reference_revisions entity (with the destination plugin 'entity_reference_revisions:paragraph')
* Secondly assign this paragraph to a parent node (by doing a lookup with the migrate process plugin) - as described in this issue: #2809793: EntityReference migrate destination

This works well. My paragraphs get migrated, and subsequently assigned to the parent node.

However I noticed an edge case which causes problems. If a node gets deleted (either manually or by rolling back the migration for that node type), the linked paragraphs also get deleted.
When I then try to do a migration rollback on the paragraphs migration, I get the following error:

Error: Call to a member function isDefaultRevision() on null in Drupal\entity_reference_revisions\Plugin\migrate\destination\EntityReferenceRevisions->rollbackNonTranslation() (line 144 of [error]
web/modules/contrib/entity_reference_revisions/src/Plugin/migrate/destination/EntityReferenceRevisions.php) #0

Proposed resolution

* Add an extra check in the rollback() function of the migrate destination plugin, to make sure the entity that is about to be deleted, does actually (still) exist.

CommentFileSizeAuthor
#2 2841650-2.patch902 bytessvendecabooter

Comments

svendecabooter created an issue. See original summary.

svendecabooter’s picture

Status: Active » Needs review
StatusFileSize
new902 bytes

Attached is a patch that fixes the fatal errors and lets the rollback process finish.

Status: Needs review » Needs work

The last submitted patch, 2: 2841650-2.patch, failed testing.

trevorbradley’s picture

Coincidentally, just struggling with this same problem this afternoon, migrating using migrate_source_csv. (Most of the server OSs that run D6 sites are hitting EOL, must be that time of the year...)

Running a "drush mr" on the content type means that the attached paragraphs cannot be rolled back (with this identical error: Line 144 of EntityReferenceRevisions.php).

You can run

drush mrs {paragraph_migration_id}
drush mi {paragraph_migration_id} --update 

to work around the error (re-importing the entire paragraphs).

EDIT: Let me try this patch out...

trevorbradley’s picture

Status: Needs work » Reviewed & tested by the community

The patch works lovely as best I can tell. No clue about that Test error - my PHP Unit is throwing an error of:

$ ~/.config/composer/vendor/bin/phpunit ../modules/entity_reference_revisions/src/Tests/EntityReferenceRevisionsDiffTest.php 
Class '../modules/entity_reference_revisions/src/Tests/EntityReferenceRevisionsDiffTest' could not be found in '/var/www/drupal8/test2.qualitycraft.com/public_html/modules/entity_reference_revisions/src/Tests/EntityReferenceRevisionsDiffTest.php'.
svendecabooter’s picture

Thanks for the review!
The PHPUnit error does seem unrelated, but I suppose maintainers have a better view on that.

kil’s picture

I'm also running into this problem when migrating data into D8 from an external not Drupal database. I can also confirm, that the patch solves the error when doing a rollback of the 'entity_reference_revisions:paragraph' migration (that is the first step of the migration as described by svendecabooter).

But it seems to me that the problem goes deeper: With the rollback of the 'entity:node' (that is the second step as described by svendecabooter) the paragraphs are deleted but migration is not informed about this (no update of the migrate_map). So migration still believes that the paragraph data is present (you can see in the migrate status for the first step that the data is marked as imported). I need to do a rollback of the first step, before I restart the second step migration, although migration status tells me that everything is imported. Otherwise the second step migration will run (and migration_dependencies is also not working, because migrate_map tells that everything is imported) but it will not apply the paragraphs data (as this data is not present anymore). As TrevorBradley pointed out, you need a re-import of the entire paragraphs. This may be no problem as long as you group your migrations and run rollback and migration for the whole group, but handling a lot of data with many migrations (and being in the process of testing the migration steps) I usually start and rollback migrations individually. In such a case the data can get a little bit of a mess if you not pay attention of this rollback relation between the first and the second step. Maybe someone has an answer for this problem (somewhere migrate_map needs to be updated)?

miro_dietiker’s picture

Status: Reviewed & tested by the community » Fixed

Committed, thx. :-)

Status: Fixed » Closed (fixed)

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