Hi,

Background: I have managed to develop some scripts that programatically update a bunch of nodes (100+) and every time I update the nodes a new revison is created.

Question: Is there a way to programtically revert a node (or a bunch of nodes) to a previous version?

Sorry if this is an entry level question as I am fairly new to Drupal and PHP, but I am enjoying it.

Many thanks in advance for any help.

Colin.

Comments

redsd’s picture

The easiest way is probally to do a:

$node_rev = node_load($nid, $vid, $reset = FALSE);
$node_rev->vid = NULL;
node_save($node_rev);

You load the node by ID(nid) and by revision ID(vid), by removing the vid and saving the node again it will be updated to an old revision with a new revision id.

colinlees’s picture

redsd,
Thanks for the advice - I'll give it a try and let you know how I get on.

Many thanks, Colin.

thorn’s picture

$node_rev = node_load($nid, $vid, $reset = FALSE);
$node_rev->revision = 1;
$node_rev->log = "Reason why we are resetting";
node_save($node_rev);