You are here

function forum_node_update in Drupal 7

Same name and namespace in other branches
  1. 8 core/modules/forum/forum.module \forum_node_update()
  2. 9 core/modules/forum/forum.module \forum_node_update()
  3. 10 core/modules/forum/forum.module \forum_node_update()

Implements hook_node_update().

File

modules/forum/forum.module, line 349
Provides discussion forums.

Code

function forum_node_update($node) {
  if (_forum_node_check_node_type($node)) {
    if (empty($node->revision) && 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();
    }
  }
}