I needed functionality for an admin to bulk-approve revisions. The client's site admin will need to print out the revised nodes and get them approved in hard copy, so he doesn't want to have to click back through them all to approve one at a time.
Revision_moderation does a nice job of queuing up revisions and provides a screen to view nodes with pending revisions, but there's no way to publish multiple revisions at once. Most of my solution involves adding functions to revision_moderation, but a core patch was required as well.
1) Install revision_moderation
2) Patch node.module to add a new hook called node_filters. See http://realize.be/extend-node-filters-form for details
3) Add the following three functions to revision_moderation.module:
/**
* Implementation of hook node_filters
* This hook does not exist without a patch to node.module
* See realize.be/extend-node-filters-form
*
* Adds a filter on admin/content/node to show nodes that have pending revisions
*
* @return unknown
*/
function revision_moderation_node_filters()
{
$options['pending'] = 'pending';
return array(
'revision' => array(
'title' => 'a revision',
'options' => $options,
'where' => 'n.nid = rm.nid
AND v.nid = n.nid
AND v.vid > n.vid',
'join' => 'INNER JOIN revision_moderation rm ON n.nid
INNER JOIN node_revisions v ON n.nid')
);
}
/**
* Implementation of hook node_operations
*
* Adds a bulk operation option to the "Update options" dropdown on
* admin/content/node
*
* @return unknown
*/
function revision_moderation_node_operations()
{
$operations = array(
'publish_pending' => array(
'label' => t('Publish most recent revision'),
'callback' => 'revision_moderation_publish_all',
)
);
return $operations;
}
/**
* Callback handler to publish the most recent revision of checked nodes
* on admin/content/node.
*/
function revision_moderation_publish_all($nids)
{
$revisions = array();
foreach ($nids as $nid)
{
$revisions = revision_moderation_get_node_pending_revisions($nid);
$newest_revision = array_shift($revisions);
//We can't use revision_moderation_publish() because it redirects
//Reproduce core functionality of revision_moderation_publish...
$node = node_load($newest_revision->nid, $newest_revision->vid);
db_query("UPDATE {node} SET vid = %d, title = '%s' WHERE nid = %d", $newest_revision->vid, $node->title, $newest_revision->nid);
watchdog('content', t('@type: published %title revision %revision', array('@type' => t($node->type), '%title' => $node->title, '%revision' => $newest_revision->vid)), WATCHDOG_NOTICE, l(t('view'), "node/$newest_revision->nid/revisions/$newest_revision->vid/view"));
}
} 4) Remove the Pending Revisions tab from revisision_moderation, since our new filter shows pretty much the same thing:
function revision_moderation_menu($may_cache) {
$items = array();
if ($may_cache) {
// An admin page listing all nodes with revisions in moderation.
/*$items[] = array(
'path' => 'admin/content/node/revisions',
'title' => t('Pending revisions'),
'callback' => 'revision_moderation_pending_revisions_admin',
'type' => MENU_LOCAL_TASK,
'access' => user_access('administer nodes'),
);*/
...
That's it. You now will have a new filter at admin/content/node that will show you all nodes that have a pending revision. You can bulk select these and use the new "Publish most recent revision" option in the "Update options" dropdown to do the job.
A note of caution, in case you missed it: this will publish the *most recent* revision only. If there are multiple revisions stacked up, any with a lower vid will be ignored.
Comments or improvements welcome!
-Gnosis
Comments
Great stuff!!! Is this
Great stuff!!! Is this applicable to Drupal 6 and Revisioning 6.x-3.7?
Bulk revisions for version 6
My developer is trying to upgrade the code to version 6 but is having some difficulty. Has anyone tried to update the code above to version 6?
Cheers,
Roly.