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.
/**
* Implementation of hook_action_info().
*/
/**
* Implements hook_action_info().
*/
function revert_last_revision_action_info() {
$action = array(
'REVERT_LAST_REVISION' => array(
'label' => t('Revert to Last Revision'),
'type' => 'node',
'configurable' => FALSE,
'triggers' => array('any'),
),
);
return $action;
}
/**
* Action function for REVERT_LAST_REVISION.
*/
function REVERT_LAST_REVISION(&$entity, $context = array()) {
$node = $entity;
$revision_list = node_revision_list($node);
unset($revision_list[$node->vid]);
if (count($revision_list) > 0) {
$last_revision = max(array_keys($revision_list));
$node_last_revision = node_load($node->nid, $last_revision);
$node_last_revision->revision = TRUE;
$node_last_revision->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->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' => array(
'label' => t('Revert to Last Revision'),
'type' => 'node',
'configurable' => FALSE,
'triggers' => array('any'),
'behavior' => array('changes_property'),
'vbo_configurable' => FALSE,
'pass rows' => TRUE,
),
);
return $action;
}
/**
* Action function for REVERT_LAST_REVISION.
*/
function REVERT_LAST_REVISION(&$entity, $context = array()) {
$revision_list = node_revision_list($entity);
unset($revision_list[$entity->vid]);
if (count($revision_list) > 0) {
$last_revision = max(array_keys($revision_list));
$entity = node_load($entity->nid, $last_revision, TRUE);
$entity->revision = TRUE;
$entity->log = "Reverted via bulk operation action.";
}
}