You are here

public function StateFlow::set_published in State Machine 7

Same name and namespace in other branches
  1. 6 modules/state_flow/plugins/state_flow.inc \StateFlow::set_published()
  2. 7.2 modules/state_flow/plugins/state_flow.inc \StateFlow::set_published()
1 call to StateFlow::set_published()
StateFlow::on_enter_published in modules/state_flow/plugins/state_flow.inc

File

modules/state_flow/plugins/state_flow.inc, line 157

Class

StateFlow

Code

public function set_published() {
  $this->object->status = 1;

  // Ensure that all other published revisions are unpublished
  $published_revs = db_query('
      SELECT vid
      FROM {node_revision_states}
      WHERE nid = :nid
      AND vid <> :vid
      AND state = :state
      ORDER BY vid DESC', array(
    ':nid' => $this->object->nid,
    ':vid' => $this->object->vid,
    ':state' => 'published',
  ))
    ->fetchAll();
  if (is_array($published_revs)) {
    foreach ($published_revs as $rev) {
      $rev_vid = isset($rev->vid) ? intval($rev->vid) : FALSE;
      $rev_node = $rev_vid ? node_load($this->object->nid, $rev_vid) : FALSE;
      if ($rev_node) {
        $rev_state = state_flow_load_state_machine($rev_node, TRUE);
        $rv = $rev_state
          ->fire_event('unpublish', NULL, t('Unpublished due to the publication of revision @vid.', array(
          '@vid' => $this->object->vid,
        )));
      }
    }
  }

  // Set the published status on the node_revision record for this revision
  $res = db_update('node_revision')
    ->fields(array(
    'status' => $this->object->status,
  ))
    ->condition('vid', $this->object->vid)
    ->execute();

  // Set the published status on the node record for this node
  $res = db_update('node')
    ->fields(array(
    'status' => $this->object->status,
  ))
    ->condition('nid', $this->object->nid)
    ->execute();

  // Update the node access table for this node.
  $node = node_load($this->object->nid, $this->object->vid, TRUE);
  node_access_acquire_grants($node);

  //rebuild taxonomy index
  if (function_exists('taxonomy_delete_node_index')) {
    taxonomy_delete_node_index($node);
  }
  if (function_exists('taxonomy_build_node_index')) {
    taxonomy_build_node_index($node);
  }
}