function forum_node_update

Implements hook_node_update().

File

drupal/core/modules/forum/forum.module, line 352
Provides discussion forums.

Code

function forum_node_update(EntityInterface $node) {
  if (_forum_node_check_node_type($node)) {

    // If this is not a new revision and does exist, update the forum record,
    // otherwise insert a new one.
    if ($node
      ->getRevisionId() == $node->original
      ->getRevisionId() && db_query('SELECT tid FROM {forum} WHERE nid=:nid', array(
      ':nid' => $node->nid,
    ))
      ->fetchField()) {
      if (!empty($node->forum_tid)) {
        db_update('forum')
          ->fields(array(
          'tid' => $node->forum_tid,
        ))
          ->condition('vid', $node->vid)
          ->execute();
      }
      else {
        db_delete('forum')
          ->condition('nid', $node->nid)
          ->execute();
      }
    }
    else {
      if (!empty($node->forum_tid)) {
        db_insert('forum')
          ->fields(array(
          'tid' => $node->forum_tid,
          'vid' => $node->vid,
          'nid' => $node->nid,
        ))
          ->execute();
      }
    }

    // If the node has a shadow forum topic, update the record for this
    // revision.
    if (!empty($node->shadow)) {
      db_delete('forum')
        ->condition('nid', $node->nid)
        ->condition('vid', $node->vid)
        ->execute();
      db_insert('forum')
        ->fields(array(
        'nid' => $node->nid,
        'vid' => $node->vid,
        'tid' => $node->forum_tid,
      ))
        ->execute();
    }
  }
}