You are here

function workbench_scheduler_moderate_unpublish in Workbench Scheduler 7

Same name and namespace in other branches
  1. 7.2 workbench_scheduler.module \workbench_scheduler_moderate_unpublish()

Unpublish a node following proper moderation workflow.

Parameters

object $node: The node to unpublish.

2 calls to workbench_scheduler_moderate_unpublish()
workbench_scheduler_process_end_dates in ./workbench_scheduler.module
Run schedules for end times / states.
workbench_scheduler_process_start_dates in ./workbench_scheduler.module
Run schedules for start times / states.

File

./workbench_scheduler.module, line 1374
Content scheduling for Workbench.

Code

function workbench_scheduler_moderate_unpublish($node) {
  module_load_include('module', 'workbench_moderation');
  module_load_include('inc', 'workbench_moderation', 'workbench_moderation.node');

  // Copied from workbench_moderation_node_unpublish_form_submit.
  // In workbench_moderation.node.inc.
  // Remove the moderation record's "published" flag.
  db_update('workbench_moderation_node_history')
    ->condition('hid', $node->workbench_moderation['published']->hid)
    ->fields(array(
    'published' => 0,
  ))
    ->execute();

  // Moderate the revision.
  workbench_moderation_moderate($node, workbench_moderation_state_none());

  // Make sure the 'current' revision is the 'live' revision.
  // I.e, 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);
}