diff -urp revisioning/revisioning_api.inc revisioning-NEW/revisioning_api.inc --- revisioning/revisioning_api.inc 2010-01-27 20:09:32.000000000 -0500 +++ revisioning-NEW/revisioning_api.inc 2010-03-17 15:51:53.000000000 -0400 @@ -312,6 +312,32 @@ function _revisioning_publish_latest_rev } /** + * Find the most recent pending revision and unpublish node. + * Note that no check is made as to whether the initiating user has permission + * to publish this node. + * + * @param $node + * The node object whose latest pending revision is to be published + * @return + * TRUE if operation was successful, FALSE if there is no pending revision to + * publish + */ +function _revisioning_unpublish_latest_revision(&$node) { + // Get latest pending revision or take the current provided it's UNpublished + $latest_pending = revisioning_get_latest_revision_id($node->nid); + if (!$latest_pending) { + if (!$node->status && $node->is_current) { + $latest_pending = $node; + } + } + if ($latest_pending) { + _revisioning_unpublish_revision($node->nid, $latest_pending->vid); + return TRUE; + } + return FALSE; +} + +/** * Return a count of the number of revisions newer than the supplied vid. * * @param $vid diff -urp revisioning/revisioning_triggers_actions.inc revisioning-NEW/revisioning_triggers_actions.inc --- revisioning/revisioning_triggers_actions.inc 2009-11-19 18:12:29.000000000 -0500 +++ revisioning-NEW/revisioning_triggers_actions.inc 2010-03-17 15:51:53.000000000 -0400 @@ -25,7 +25,7 @@ function revisioning_hook_info() { 'unpublish' => array( 'runs when' => t('When unpublishing the current revision'), ), - ), + ), ), ); } @@ -89,8 +89,16 @@ function revisioning_action_info() { // Don't need 'changes_node_property'; it will generate a superfluous "save // post" action; we're alreay making sure db is updated // 'behavior' => array('changes_node_property') - ) - ); + ), + 'revisioning_unpublish_revision_action' => array( + 'type' => 'node', + 'description' => t('Unpublish revision'), + 'configurable' => FALSE, + 'hooks' => array( + 'nodeapi' => array('presave'), + ), + ) + ); } /** @@ -108,3 +116,19 @@ function revisioning_publish_latest_revi drupal_set_message(t('"!title" has no pending revision to be published.', array('!title' => $node->title)), 'warning'); } } + +/** + * Implementation of unpublish_latest_revision action + */ +function revisioning_unpublish_revision_action(&$node, $context = array()) { + $type = node_get_types('name', $node->type); + watchdog('revisioning', + 'Executing unpublish_revision action for @type %title', array('@type' => $type, '%title' => $node->title), + WATCHDOG_NOTICE, l(t('view'), "node/$node->nid")); + if (_revisioning_unpublish_latest_revision($node)) { + drupal_set_message(t('Revision has been unpublished.')); + } + else { + drupal_set_message(t('"!title" has no revision published.', array('!title' => $node->title)), 'warning'); + } +}