You are here

function _revisioning_publish_revision in Revisioning 7

Same name and namespace in other branches
  1. 8 revisioning_api.inc \_revisioning_publish_revision()
  2. 6.4 revisioning_api.inc \_revisioning_publish_revision()
  3. 6 revisioning.module \_revisioning_publish_revision()
  4. 6.3 revisioning_api.inc \_revisioning_publish_revision()

Make the supplied revision of the node current and publish it.

It is the caller's responsibility to provide a proper revision. Note that no check is made as to whether the initiating user has permission to publish this revision.

Parameters

int $node_revision: Target $node object (loaded with target revision)

bool $clear_cache: Whether to clear the cache afterwards or not. Clearing the cache on every node during bulk operations can be time-consuming.

3 calls to _revisioning_publish_revision()
revisioning_publish_confirm_submit in ./revisioning.pages.inc
Submission handler for the publish_confirm form.
revisioning_scheduler_cron in revisioning_scheduler/revisioning_scheduler.module
Implements hook_cron().
_revisioning_publish_latest_revision in ./revisioning_api.inc
Publish latest revision.

File

./revisioning_api.inc, line 486
API functions of Revisioning module

Code

function _revisioning_publish_revision(&$node_revision, $clear_cache = TRUE) {
  $return = module_invoke_all('revisionapi', 'pre publish', $node_revision);
  if (in_array(FALSE, $return)) {
    drupal_goto('node/' . $node_revision->nid . '/revisions/' . $node_revision->vid . '/view');
  }

  // Update {node} and {node_revision} tables setting status and other flags.
  db_update('node')
    ->fields(array(
    'vid' => $node_revision->vid,
    'title' => $node_revision->title,
    'changed' => time(),
    'status' => NODE_PUBLISHED,
    'comment' => $node_revision->comment,
    'promote' => $node_revision->promote,
    'sticky' => $node_revision->sticky,
  ))
    ->condition('nid', $node_revision->nid)
    ->execute();
  db_update('node_revision')
    ->fields(array(
    'status' => NODE_PUBLISHED,
  ))
    ->condition('vid', $node_revision->vid)
    ->execute();
  if (empty($node_revision->is_current)) {

    // Need to set up $node_revision correctly before calling
    // revisioning_update_taxonomy_index(), via revisioning_node_update().
    $node_revision->current_revision_id = $node_revision->vid;
  }
  $node_revision->status = $node_revision->current_status = NODE_PUBLISHED;

  // Make sure the alias, if present, is not changed when publishing.
  if (!isset($node_revision->path['pathauto'])) {
    $node_revision->path = array(
      // So that path_node_update() does nothing.
      'alias' => '',
      // So that pathauto_node_update() does nothing.
      'pathauto' => FALSE,
    );
  }
  elseif (!isset($node_revision->path['alias'])) {

    // [#1328180], [#1576552]
    $node_revision->path['alias'] = '';
  }

  // Make sure the menu, if present, is not changed when publishing [#1698024]
  if (!isset($node_revision->menu)) {
    $node_revision->menu = array(
      'enabled' => '',
      'mlid' => '',
      'link_title' => '',
      'link_path' => '',
      'description' => '',
    );
  }
  elseif (!isset($node_revision->menu)) {
    $node_revision->menu = '';
  }
  $node_revision->original = clone $node_revision;
  $node_revision->original->status = NODE_NOT_PUBLISHED;
  module_invoke_all('node_update', $node_revision);
  module_invoke_all('entity_update', $node_revision, 'node');

  // Update node_access table only for existing nodes. When the node is newly
  // created via the node/add page, node_access_acquire_grants() is called by
  // node_save() anyway. See [#1243018].
  if (empty($node_revision->is_new)) {
    node_access_acquire_grants($node_revision);
  }
  if ($clear_cache) {
    cache_clear_all();
  }
  watchdog('content', 'Published rev #%revision of @type %title', array(
    '@type' => $node_revision->type,
    '%title' => $node_revision->title,
    '%revision' => $node_revision->vid,
  ), WATCHDOG_NOTICE, l(t('view'), "node/{$node_revision->nid}/revisions/{$node_revision->vid}/view"));
  module_invoke_all('revisionapi', 'post publish', $node_revision);
}