Problem/Motivation

This test in function WorkflowTransitionForm::submitForm() on line 467 in file includes/Form/WorkflowTransitionForm.phpfor 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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

johnv’s picture

Does checking for $entity->is_new help? I guess in your case is_new=TRUE .

kaare’s picture

Like this? Yes, that works. Dunno if that's enough for a proper entity edit mode check, though.

johnv’s picture

Priority: Major » Normal

I 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.

kaare’s picture

As a workaround during migration I've implemented two node internal hooks (node_content_insert() and node_content_update()) which are ran after drupal_write_record() but prior to field_attach_insert() during node_save(). Within these I reset the $node->changed flag to the original (REQUEST_TIME), causing this bug not to be triggered.

  • johnv committed e880557 on 7.x-2.x
    Issue #2430243: Fixed fragile check for entity edit mode in...
johnv’s picture

Version: 7.x-2.x-dev » 7.x-2.5
Status: Active » Fixed

I settled for above fix.Thanks.

Status: Fixed » Closed (fixed)

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