Given that any hope of #218755: Support revisions in different states being implemented in D7 is quickly dwindling as the code freeze approaches, and in light of conversations taking place in #282122: D7UX: "Save draft" and "Publish" buttons on node forms, I propose that we take the small but extremely significant step of adding status, draft, promote and sticky fields to the node_revision table.

These fields would remain in the node table as well, but be duplicated in the node_revisions table. This would be a HUGE boon for anyone working on modules dealing with content moderation and workflow. It would prevent the need for many complicated hacks and workarounds while greatly increasing the scope of what can be accomplished in contrib. Given that we're leaving the fields in the node table, I don't expect this will have any substantial downside, but the potential upside is tremendous!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

catch’s picture

I have a feeling that if we just add the fields in the schema, drupal_write_record() will handle writing to them for us, so this could be a very small change.

jstoller’s picture

Great! How do we make that happen?

Damien Tournoud’s picture

Status: Active » Needs review
FileSize
4.24 KB

Here is an (untested) patch.

Damien Tournoud’s picture

Moshe noted that we need to load those columns from the node_revision table now.

Damien Tournoud’s picture

And a less-broken patch.

yched’s picture

I'm not sure sticking the update in the existing node_update_7005() for 'body as field' is a good idea. Saves duplicating the overall structure of the function, but those are two really unrelated updates...
At any rate, note that node_update_7005() only acts on node types with $info->has_body == TRUE, which is not what we want here.

Damien Tournoud’s picture

An even less broken one.

Damien Tournoud’s picture

This one should do it, and fix the issue raised by yched in #6. I do think it makes total sense to do both operations at the same time.

moshe weitzman’s picture

Status: Needs review » Needs work
+++ modules/node/node.install
@@ -488,6 +525,19 @@ function node_update_7005(&$context) {
+        // Migrate the status columns to the {node_revision} table.
+        db_update('node_revision')
+          ->fields(array(
+            'vid' => $revision->vid,
+            'status' => $revision->status,
+            'comment' => $revision->comment,
+            'promote' => $revision->promote,
+            'moderate' => $revision->moderate,
+            'sticky' => $revision->sticky,
+          ))
+          ->condition('vid', $revision->vid)
+          ->execute();

Can we not populate node_revision with a single SQL statement that features a subquery? If successful, it probably does make sense to separate the node_revision migration from body as field.

Damien Tournoud’s picture

No, there is no such thing as UPDATE FROM SELECT (as there is INSERT FROM SELECT).

moshe weitzman’s picture

Status: Needs work » Needs review
RdeBoer’s picture

Agree with jstoller this was long overdue. Big thank you to all others in this thread for making this happen.
Rik

jstoller’s picture

This patch will likely need to be updated based on what's happening in #282122: D7UX: "Save draft" and "Publish" buttons on node forms.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community
Dries’s picture

Status: Reviewed & tested by the community » Fixed

This looks like a great first step. Thanks!

webchick’s picture

Oh, excellent!

This patch was off my radar, but would've made writing Revision Moderation module sooooo much easier!

RdeBoer’s picture

Errr.... marked as "fixed" ?

As jstoller mentions in #13. The patch is subject to change as a result of developments in #282122: D7UX: "Save draft" and "Publish" buttons on node forms, in particular comment #160, regarding the "(published) status" flag.

The published info is already covered by the "status" flag on node. Having this flag on the revision table as well is unnecessary and inefficient. Furthermore it will open the door to confusion and possible data inconsistencies. There can be at most one revision that is published. But with a status flag on revision it will be possible to create pathological cases where more than one draft/revision have their published flags set.

By contrast, again referring to #282122, comment #160, a more generic "state" field on revision would be brilliant!

So, in the patch just change the word "status" to "state" (or "workflow", as Dries prefers in comment #161 and we're done!

.....except maybe for the moderate flag...
As far as I know "moderate" is already obsolete on node, what is the idea behind reviving it for node-revision?

jstoller’s picture

Status: Fixed » Needs work

Based on the current standing of #282122: D7UX: "Save draft" and "Publish" buttons on node forms, the changes from the current patch here are:

  1. 'status' should be removed from {node_revisions}
  2. In the {node} table, 'status' should be renamed 'published' to prevent confusion with our new 'state' field
  3. 'moderate' is a node property and should only appear in the {node} table
  4. Add a 'state' field to {node_revisions}
  5. Add a 'last_state' field to {node_revisions}
  6. The 'timestamp' field in {node_revisions} should be replaced by 'created' and 'changed' fields, just like those in {node}

I think that's it, but please check #282122: D7UX: "Save draft" and "Publish" buttons on node forms for the details and any further changes. Alas, I will be out of town until code freeze.

xtfer’s picture

Status: Needs work » Fixed

As far as I can tell, #8 has been committed in the nightly of 22nd August. Im guessing the comments at #17 & #18 should be a new issue.

Status: Fixed » Closed (fixed)

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