Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
This test in function WorkflowTransitionForm::submitForm()
on line 467 in file includes/Form/WorkflowTransitionForm.php
for whether one is in a entity edit mode is too fragile:
if ((isset($entity->changed)) && $entity->changed == REQUEST_TIME) {
During migration of content I've implemented hook_node_presave()
that changes $entity->changed
to the time it actually was changed from the source database. This causes a nested node_save()
→ entity_save()
→ node_save()
for the same node. Luckily an exception is thrown so it doesn't recurse endlessly.
Proposed resolution
Find a better test for whether one is in a entity edit mode or not.
Comment | File | Size | Author |
---|---|---|---|
#2 | workflow-2430243-fragile_entity_edit_check-2.patch | 882 bytes | kaare |
Comments
Comment #1
johnvDoes checking for
$entity->is_new
help? I guess in your case is_new=TRUE .Comment #2
kaareLike this? Yes, that works. Dunno if that's enough for a proper entity edit mode check, though.
Comment #3
johnvI don't think that is enough. IMO both should be combined. I cannot inspect the code right now - think this line is to prevent a 'rule' to happen twice.
Comment #4
kaareAs a workaround during migration I've implemented two node internal hooks (
node_content_insert()
andnode_content_update()
) which are ran afterdrupal_write_record()
but prior tofield_attach_insert()
duringnode_save()
. Within these I reset the $node->changed flag to the original (REQUEST_TIME
), causing this bug not to be triggered.Comment #6
johnvI settled for above fix.Thanks.