node_revision_rollback

Versions
4.6
node_revision_rollback($nid, $revision)

Roll back to the revision with the specified revision number.

▾ 2 functions call node_revision_rollback()

node_page in modules/node.module
Menu callback; dispatches control to the appropriate operation handler.
queue_vote in modules/queue.module

Code

modules/node.module, line 1036

<?php
function node_revision_rollback($nid, $revision) {
  global $user;
  if (user_access('administer nodes')) {
    $node = node_load(array('nid' => $nid));
    // Extract the specified revision:
    $rev = $node->revisions[$revision]['node'];
    if ($_POST['edit']['confirm']) {
      // Inherit all the past revisions:
      $rev->revisions = $node->revisions;
      // Save the original/current node:
      $rev->revisions[] = array('uid' => $user->uid, 'timestamp' => time(), 'node' => $node);
      // Remove the specified revision:
      unset($rev->revisions[$revision]);
      // Save the node:
      foreach ($node as $key => $value) {
        $filter[] = $key;
      }
      node_save($rev, $filter);
      drupal_set_message(t('Rolled back to revision %revision of %title', array('%revision' => "<em>#$revision</em>", '%title' => theme('placeholder', $node->title))));
      drupal_goto('node/'. $nid .'/revisions');
    }
    else {
      $output = theme('confirm',
                      t('Are you sure you want to revert %title? to the revision from %revision-date?', array('%title' => theme('placeholder', $node->title), '%revision-date' => theme('placeholder', format_date($node->revisions[$revision]['timestamp'])))),
                      'node/'. $nid .'/revisions',
                      t('This action cannot be undone.'),
                      t('Revert'));
      print theme('page', $output);
    }
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.