Problem/Motivation
Got this error while migrating webform submission records
[error] Error: Call to a member function invokeHandlers() on null in Drupal\webform\Entity\WebformSubmission::preCreate()
(line 835 of /app/web/modules/contrib/webform/src/Entity/WebformSubmission.php) #0 /app/web/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(87): Drupal\webform\Entity\WebformSubmission::preCreate()
#1 /app/web/modules/contrib/webform/src/WebformSubmissionStorage.php(932): Drupal\Core\Entity\ContentEntityStorageBase->create()
This error happens when the webform for the particular submission record no longer exists.
Proposed resolution
To fix this issue, at prepareRow function for D7WebformSubmission.php, check nid of the webform_submission record actually exist in the drupal, if it doesn't exist assign NULL for webform_id field
Also tweak d7_webform_submission.yml to skip if webform_id field is NULL
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | webform_migrate-skip-orphaned-submissions-3306285-3.patch | 1.42 KB | cyoon84 |
Issue fork webform_migrate-3306285
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
cyoon84 commentedComment #3
cyoon84 commentedComment #6
solideogloria commentedI created a merge request that incorporates #3, because #3 didn't apply to dev. However, instead of a straight reroll, I changed the entityQuery to use
count()and check if the count > 0, rather than loading the node's actual data.I ran a migration with the changes, and it works and fixes the error. Please review.
Comment #7
danflanagan8I solved this entirely in the yaml with the help of Migrate Conditions.
You could probably do it with just core process plugins like so:
but that's un-tested.
Comment #8
solideogloria commentedThe module shouldn't be so hard to use that you have to add another module for something like that. I think it makes more sense for the submission migration to automatically check if a webform exists before trying to migrate a submission.
Comment #9
danflanagan8The module assumes that you're migrating all the webforms, which is a reasonable assumption, especially given that when you delete a webform through the UI all the submissions get deleted. I have a case now where we didn't migrate closed webforms. That's a special case that not unreasonable requires some extra work.
Also, I showed how the skip could be done with core process plugins. I just think it looks nicer with the contrib ones. A
migration_lookupcould be done in place of theentity_existscall too.entity_existsis in core but it's not actually used in core.migration_lookupis more familiar.Comment #10
solideogloria commentedIt would need to be this (just add the webform_id field):
Then it works.