When saving an unpublished revision under moderation, the successful update status message uses the incorrect title, if the revision being saved has a different title than the published revision.

Assume you have a node type called Article. You have a published article for which the published revision has title "Title A". You edit and create a new revision under moderation with the title changed to "Title B". When you save the revision the status message that appears reads

"Article Title A has been updated"

The root cause is the altering of the reference to the node revision under save introduced by #2037655.

/**
 * Implements hook_node_access_records().
 *
 * Replaces all node properties and fields to those of the current node,
 * so node access modules implementing this hook do not use values
 * from revisions that are still in moderation.
 */
function revisioning_node_access_records($node) {

  if (!revisioning_revision_is_current($node)) {
    // For the sake of _revisioning_form_submit().
    drupal_static('revisioning_saved_node', clone $node);

    $current_node = node_load($node->nid, NULL, TRUE);
    foreach (get_object_vars($node) as $k => $value) {
      unset($node->$k);
      if (isset($current_node->$k)) {
        $node->$k = $current_node->$k;
      }
    }
  }
  return array();
}

The message is generated in the node modules form submit handler, after Revisioning has altered the node reference.

/**
 * Form submission handler for node_form().
 *
 * @see node_form()
 * @see node_form_validate()
 */
function node_form_submit($form, &$form_state) {
  $node = node_form_submit_build_node($form, $form_state);
  $insert = empty($node->nid);
  node_save($node);
  $node_link = l(t('view'), 'node/' . $node->nid);
  $watchdog_args = array('@type' => $node->type, '%title' => $node->title);
  $t_args = array('@type' => node_type_get_name($node), '%title' => $node->title);

  if ($insert) {
    watchdog('content', '@type: added %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link);
    drupal_set_message(t('@type %title has been created.', $t_args));
  }
  else {
    watchdog('content', '@type: updated %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link);
    drupal_set_message(t('@type %title has been updated.', $t_args));
  }
  if ($node->nid) {
    $form_state['values']['nid'] = $node->nid;
    $form_state['nid'] = $node->nid;
    $form_state['redirect'] = node_access('view', $node) ? 'node/' . $node->nid : '<front>';
  }
  else {
    // In the unlikely case something went wrong on save, the node will be
    // rebuilt and node form redisplayed the same way as in preview.
    drupal_set_message(t('The post could not be saved.'), 'error');
    $form_state['rebuild'] = TRUE;
  }
  // Clear the page and block caches.
  cache_clear_all();
}

Comments

fbrooks’s picture

Title: Incorrect Title Used in Status Message When Saving a Revision Under Moderation With Editing Title » Incorrect Title Used in Status Message When Saving a Revision Under Moderation With Edited Title
rdeboer’s picture

Can anyone confirm this is solved with the application of this patch from #2037655: Node access modules use wrong revision when revision moderation is used, comment #21?

fbrooks’s picture

I have confirmed that the patch in comment #21 resolves it.

rdeboer’s picture

Status: Active » Fixed

Great. Marking as fixed then.
Thanks Frank.
Rik

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.