1

(I am using Revisioning.) I call node_load(nid, vid) (with the latest version id), give new values to some fields, and then save the node. Setting $node->is_current = TRUE before saving will ensure that this version of the node is now published. However, it does not create a new revision. So I try setting $node->revision = TRUE also, but this creates a new unpublished revision which is not what I would expect.

How can I edit a node, and save it as a new revision and also as the current published revision? Not sure if it is a bug in the module.

// Node has some new revisions since the version that is currently published.
$vid = revisioning_get_latest_revision_id($nid);
$node = node_load($nid, $vid);
$node->revision = TRUE;
$node->is_current = TRUE;
$node->status = 1;
node_save($node);
// New revision created, but not published.
3

I think it will work when you explicitly set revision_moderation to FALSE. If moderation is not required, it should be published right away.

$vid = revisioning_get_latest_revision_id($nid);
$node = node_load($nid, $vid);
$node->revision = TRUE;
$node->is_current = TRUE;
$node->status = 1;
$node->revision_moderation = FALSE;
node_save($node);

From the example here: http://drupalprogrammatically.com/anwsers/7/create-node

Poster of above url also sets $node->revision = FALSE;, but that would give me the impression no new revision is saved, which is not what you want. I hope it helps.

  • This is the missing piece! Thank you for finding this! – digitgopher Apr 13 '16 at 20:04
-1

Too easy - just separate the steps. First set a new revision and save, then load it again and adjust the fields and set published and save.

  • This is not ideal and has become a performance issue. I'm updating a lot of nodes :/ – digitgopher Apr 12 '16 at 22:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.