You are here

function workbench_moderation_store in Workbench Moderation 7

Shutdown callback for saving a node revision.

This function is called by drupal_register_shutdown_function(). The purpose is to delay a node_save() call so that a live revision is not called during hook_node_update().

Instead, we delay the update until the new revision is saved. This way, we can more safely call the revision and pick up changes to items that are not revisioned (such as menu and path assignments).

Parameters

$node: The node being saved.

See also

workbench_moderation_moderate()

1 string reference to 'workbench_moderation_store'
workbench_moderation_moderate in ./workbench_moderation.module
Provide quick moderation of nodes.

File

./workbench_moderation.module, line 1754
Content moderation for Workbench.

Code

function workbench_moderation_store($node) {
  if (!isset($node->nid)) {
    watchdog('Workbench moderation', 'Failed to save node revision: node not passed to shutdown function.', array(), WATCHDOG_NOTICE);
    return;
  }
  watchdog('Workbench moderation', 'Saved node revision: %node as live version for node %live.', array(
    '%node' => $node->vid,
    '%live' => $node->nid,
  ), WATCHDOG_NOTICE, l($node->title, 'node/' . $node->nid));

  // If we are saving a published node, work from the live revision, otherwise
  // make sure that the entry in the {node} table points to the current
  // revision.
  if (empty($node->workbench_moderation['current']->unpublishing)) {
    $live_revision = workbench_moderation_node_live_load($node);
    $live_revision->status = 1;
  }
  else {
    $live_revision = workbench_moderation_node_current_load($node);
    $live_revision->status = 0;
  }

  // Don't create a new revision.
  $live_revision->revision = 0;

  // Prevent another moderation record from being written.
  $live_revision->workbench_moderation['updating_live_revision'] = TRUE;

  // Reset flag from taxonomy_field_update() so that {taxonomy_index} values aren't written twice.
  $taxonomy_index_flag =& drupal_static('taxonomy_field_update', array());
  unset($taxonomy_index_flag[$node->nid]);

  // Ensure we do not have field translations belonging to a draft revision in
  // the field data tables.
  $empty_values = array_fill_keys(array_keys(language_list()), array());
  foreach (field_info_instances('node', $live_revision->type) as $field_name => $instance) {
    $field = field_info_field($field_name);
    if (!empty($live_revision->{$field_name}) && field_is_translatable('node', $field)) {
      $live_revision->{$field_name} += $empty_values;
    }
  }

  // Save the node.
  node_save($live_revision);
}