function revisioning_nodeapi in Revisioning 6
Same name and namespace in other branches
- 6.4 revisioning.module \revisioning_nodeapi()
- 6.3 revisioning.module \revisioning_nodeapi()
Implementation of hook_nodeapi().
File
- ./revisioning.module, line 155 
Code
function revisioning_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  $args = arg();
  // Only interested in URIs that start with "node/<nid>"
  if ($args[0] != 'node' || !is_numeric($args[1])) {
    return;
  }
  switch ($op) {
    case 'alter':
    case 'delete':
    case 'load':
    case 'validate':
      return;
    case 'insert':
      if ($node->status) {
        drupal_set_message(t('Initial revision created and published.'));
      }
      else {
        drupal_set_message(t('Initial revision created, pending publication.'));
      }
      return;
    case 'view':
      if (!$teaser) {
        // this test may be superfluous
        _handle_view_op($node);
      }
      return;
  }
  if (end($args) == 'edit') {
    if ($op == 'prepare') {
      $count = _number_of_revisions_newer_than($node->vid, $node->nid);
      if ($count == 1) {
        drupal_set_message(t('Please note there is one revision more recent than the one you are about to edit.'), 'warning');
      }
      elseif ($count > 1) {
        drupal_set_message(t('Please note there are !count revisions more recent than the one you are about to edit.', array(
          '!count' => $count,
        )), 'warning');
      }
    }
    // Check if "Revisions in moderation" box ticked under Workflow options
    if ($node->revision_moderation) {
      switch ($op) {
        case 'presave':
          // called from start of node_save()
          $current_revision = _get_current_revision($node->nid);
          // Save the vid for subsequent restore during 'update' op
          $node->original_vid = $current_revision->vid;
          $node->original_revision = $node->revision;
          $pending = $node->vid > $current_revision->vid || $node->vid == $current_revision->vid && !$node->status;
          if ($node->revision && $pending) {
            // Not creating new revision as this revision is still pending
            $node->revision = FALSE;
          }
          break;
        case 'update':
          // called from end of node_save(), after _node_save_revision()
          $node->revision = $node->original_revision;
          if (isset($node->original_vid)) {
            // Resetting node vid back to its originial value, thus creating pending revision
            db_query("UPDATE {node} SET vid=%d WHERE nid=%d", $node->original_vid, $node->nid);
          }
          break;
      }
    }
    elseif ($op == 'update') {
      drupal_set_message(t('Your changes are now current as moderation is switched off for this content.'), 'warning');
    }
  }
}