Community

How to Programatically revert a node to a previous version?

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

The easiest way is probally

The easiest way is probally to do a:

<?php
$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.

redsd, Thanks for the advice

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

Many thanks, Colin.

nobody click here