"Revert to last revision" action I made an update to a site for global search and replace of text across nodes and was too far-reaching. For a specific content type I need to revert my Node update of ~500 nodes.

I found this solution in the VBO issue queue:
https://www.drupal.org/node/1166630

But in evaluating this code a new revision is made by it is not set as the current revision of the node. If I visit the node revisions page and invoke node_revision_revert_confirm_submit a new current_revision is set for the node.


Code I'm trying:

/**
 * Implementation of hook_action_info().
 */
/**
 * Implements hook_action_info().
 */
function revert_last_revision_action_info() {
  $action = array(
    'REVERT_LAST_REVISION' =&gt; array(
      'label'        =&gt; t('Revert to Last Revision'),
      'type'         =&gt; 'node',
      'configurable' =&gt; FALSE,
      'triggers'     =&gt; array('any'),
    ),
  );
  return $action;
}

/**
 * Action function for REVERT_LAST_REVISION.
 */
function REVERT_LAST_REVISION(&amp;$entity, $context = array()) {
  $node = $entity;
  $revision_list = node_revision_list($node);
  unset($revision_list[$node-&gt;vid]);
  if (count($revision_list) &gt; 0) {
    $last_revision = max(array_keys($revision_list));
    $node_last_revision = node_load($node-&gt;nid, $last_revision);
    $node_last_revision-&gt;revision = TRUE;
    $node_last_revision-&gt;log = "Reverted via bulk operation action."; // Log message
    dpm($node_last_revision, __FUNCTION__);
    node_save($node_last_revision);
  }
}


Using devel the $node arrays look the same so I'm confused as to why my revert revision code snippet is not making the new revision the current_revision. The only thing node_revision_revert_confirm_submit is doing is setting $node-&gt;revision = TRUE and calling node_save().

Anyone have any ideas?

EDIT: 11/16/2015

As others have mentioned perhaps this has to do with how VBO is initiating the action.

I've also tried the below code but the Node isn't saved.

/**
 * Implements hook_action_info().
 */
function revert_last_revision_action_info() {
  $action = array(
    'REVERT_LAST_REVISION' =&gt; array(
      'label'        =&gt; t('Revert to Last Revision'),
      'type'         =&gt; 'node',
      'configurable' =&gt; FALSE,
      'triggers'     =&gt; array('any'),
      'behavior'     =&gt; array('changes_property'),
      'vbo_configurable' =&gt; FALSE,
      'pass rows'        =&gt; TRUE,
    ),
  );
  return $action;
}

/**
 * Action function for REVERT_LAST_REVISION.
 */
function REVERT_LAST_REVISION(&amp;$entity, $context = array()) {
  $revision_list = node_revision_list($entity);
  unset($revision_list[$entity-&gt;vid]);
  if (count($revision_list) &gt; 0) {
    $last_revision = max(array_keys($revision_list));
    $entity = node_load($entity-&gt;nid, $last_revision, TRUE);
    $entity-&gt;revision = TRUE;
    $entity-&gt;log = "Reverted via bulk operation action.";
  }
}
After much debugging this appears to work. This code appears to revert to the most recent revision properly and does not cause a 2nd node save to occur:

/**
 * Implements hook_action_info().
 */
function revert_last_revision_action_info() {
  $action = array(
    'REVERT_LAST_REVISION' =&gt; array(
      'label'        =&gt; t('Revert to Last Revision'),
      'type'         =&gt; 'node',
      'configurable' =&gt; FALSE,
      'triggers'     =&gt; array('any'),
      'behavior'     =&gt; array('view_property'),
    ),
  );
  return $action;
}

/**
 * Action function for REVERT_LAST_REVISION.
 */
function REVERT_LAST_REVISION(&amp;$entity, $context = array()) {
  $revision_list = node_revision_list($entity);
  unset($revision_list[$entity-&gt;vid]);
  if (count($revision_list) &gt; 0) {
    $last_revision = max(array_keys($revision_list));
    $entity = entity_revision_load('node', $last_revision);
    $entity-&gt;revision = TRUE;
    $entity-&gt;log = "Reverted via bulk operation action.";
    entity_save('node', $entity);
  }
}


Does anyone know what is causing the final node save in ViewsBulkOperationsAction::execute to not fire? I can't tell if it's because of the action info behaviors not set as: save, pre-save, or changes_property values. Or perhaps it's the usage of entity_save here  instead of a node_save ...

I've debugged this with a few nodes using Batch and single nodes.