Problem/Motivation

It appears that workbench moderation default states are being ignored in oa_files_create_document() -- when an oa_wiki_page node is created. The pub

Workbench moderation implements hook_node_presave() which determines the node status before saving the new node:

function workbench_moderation_node_presave($node) {
  global $user;
  if (isset($node->workbench_moderation_state_new)) {
    // If the new moderation state is published, or if this revision is the
    // published revision, set the node status to published.
    if ($node->workbench_moderation_state_new == workbench_moderation_state_published() || (!empty($node->workbench_moderation['published']) && $node->vid == $node->workbench_moderation['published']->vid)) {
      $node->status = 1;
    }
    else {
      $node->status = 0;
    }
  }
}

Since this new oa_wiki_page node is being programmatically created (without all of the attachment involved when creating the node via node add form), workbench doesn't know to check to see if this node should be moderated and thus the workbench_moderation_state_new property is not set on the node.

Proposed resolution

I think that this can be solved adding a check in oa_files_create_document() before the node_save():

if (module_exists('workbench_moderation')) {
  $node->workbench_moderation_state_new = variable_get('workbench_moderation_default_state_' . $node->type, workbench_moderation_state_none());
}

I'm not sure if it's more desirable to use: module_exists('oa_workbench'), or have a helpful message like what's already setup in oa_files_update_document(), line 480 of oa_files.module

if (module_exists('oa_workbench')) {
  drupal_set_message(t('New draft of <a href="@url">@title</a> created.', array('@title' => $node->title, '@url' => url('node/' . $node->nid))));
}
else {
  drupal_set_message(t('Document <a href="@url">@title</a> updated.', array('@title' => $node->title, '@url' => url('node/' . $node->nid))));
}

Remaining tasks

1. Determine if need a message different message posted a new Document node is created or the following is still OK:

drupal_set_message(t('Document <a href="@url">@title</a> created.', array('@title' => $node->title, '@url' => url('node/' . $node->nid))));
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mirie’s picture

mpotter’s picture

Status: Active » Fixed

Committed this to 5b7aeca. I'm not concerned with the message, but if it's a big deal to somebody they can submit a new patch in a new issue. Thanks for tracking this down!

Status: Fixed » Closed (fixed)

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