diff --git a/workbench_moderation.module b/workbench_moderation.module index f510e2e..aab06bd 100644 --- a/workbench_moderation.module +++ b/workbench_moderation.module @@ -675,13 +675,30 @@ function workbench_moderation_node_update($node) { return; } - // Set default moderation state values. + // Set moderation state values. if (!isset($node->workbench_moderation_state_current)) { - $node->workbench_moderation_state_current = ($node->status ? workbench_moderation_state_published() : workbench_moderation_state_none()); - }; + $node->workbench_moderation_state_current = !empty($node->original->workbench_moderation['current']->state) ? $node->original->workbench_moderation['current']->state : workbench_moderation_state_none(); + } if (!isset($node->workbench_moderation_state_new)) { - $node->workbench_moderation_state_new = variable_get('workbench_moderation_default_state_' . $node->type, workbench_moderation_state_none()); - }; + // Moving from published to unpublished. + if ($node->status == NODE_NOT_PUBLISHED && isset($node->original->status) && $node->original->status == NODE_PUBLISHED) { + $node->workbench_moderation_state_new = variable_get('workbench_moderation_default_state_' . $node->type, workbench_moderation_state_none()); + $sync_live = true; + + } + // Moving from unpublished to published. + elseif ($node->status == NODE_PUBLISHED && isset($node->original->status) && $node->original->status == NODE_NOT_PUBLISHED) { + $node->workbench_moderation_state_new = workbench_moderation_state_published(); + } + else { + if (!empty($node->original->workbench_moderation['current']->state)) { + $node->workbench_moderation_state_new = $node->original->workbench_moderation['current']->state; + } + else { + $node->workbench_moderation_state_new = variable_get('workbench_moderation_default_state_' . $node->type, workbench_moderation_state_none()); + } + } + } // If this is a new node, give it some information about 'my revision'. if (!isset($node->workbench_moderation)) { @@ -705,6 +722,17 @@ function workbench_moderation_node_update($node) { field_attach_update('node', $node); // Moderate the node. workbench_moderation_moderate($node, $node->workbench_moderation_state_new); + + if (isset($sync_live) && $sync_live) { + // Make sure the 'current' revision is the 'live' revision -- ie, the revision + // in {node}. + $live_revision = workbench_moderation_node_current_load($node); + $live_revision->status = 0; + $live_revision->revision = 0; + $live_revision->workbench_moderation['updating_live_revision'] = TRUE; + // @TODO: do we trust node_save() here? + node_save($live_revision); + } } return;