When Drafty is responsible for maintaining the entity base_table it's imperative to correctly determine the cases when a published revision needs to be pushed forward and resaved in the entity base_table. Drafty uses the $is_draft_revision flag to detect this situations and state_flow_entity is responsible to set that when appropriate.
I narrowed down two cases when state_flow_entity failed to do so in StateFlowEntity::isDraftRevision().

  • New node
    1. create a new draft node
    2. edit the draft node and save it as a draft again
    3. state_flow_entity doesn't check if there is an existing published revision, sets the $is_draft_revision flag to TRUE and Drafty in turn resaves the previous draft revision
  • Editing a draft
    1. move a node into the draft/unpublished state
    2. edit the draft node and save it as a draft again
    3. state_flow_entity doesn't set the $is_draft_revision flag, Drafty won't be triggered, node table will contain the entry for the unpublished revision

Comments

paranojik created an issue. See original summary.

paranojik’s picture

Status: Active » Needs review
StatusFileSize
new1.47 KB

This patch tries to fix the isDraftRevision() method.

paranojik’s picture

The previous patch broke a couple of test by not properly determining the "unpublished" state.
New patch attached. Big thanks to @das-peter for suggesting this solution.

das-peter’s picture

Thanks, looks pretty good :) All current tests pass. However, may I ask you to create new tests that would fail with the unpatched module version?

LittleRedHen’s picture

Thanks for this! I was struggling with the new-draft-of-published-content thing as well, when the second save on a new draft (such as to submit it for approval) was un-publishing the old published version. My minimal testing so far indicates that the patch in #3 corrects that.

I do notice, though, is that the state information which appears on the node-view page for users with sufficient privileges still says

Most recent revision: Yes

, even when there is a newer draft. So it looks like the $state_machine->get_latest_revision() may not be correct now. I will look into that further, but the patch in #3 certainly helps.

das-peter’s picture

@LittleRedHen Thanks for the feedback, much appreciated!

paranojik’s picture

StatusFileSize
new3.73 KB

Added test for the "Editing a draft" case. I'm not able to reproduce the "New node" case anymore. Maybe that was a product of my imagination...

  • das-peter committed 5b765f6 on 7.x-3.x authored by paranojik
    Issue #2576673 by paranojik, das-peter, LittleRedHen: Saving a draft...
das-peter’s picture

Status: Needs review » Fixed

Seems to work beautifully and the test fails without patched code - perfect :)
Thanks!

Status: Fixed » Closed (fixed)

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