function forum_node_update

Same name in other branches
  1. 9 core/modules/forum/forum.module \forum_node_update()
  2. 8.9.x core/modules/forum/forum.module \forum_node_update()
  3. 10 core/modules/forum/forum.module \forum_node_update()
  4. 11.x core/modules/forum/forum.module \forum_node_update()

Implements hook_node_update().

File

modules/forum/forum.module, line 349

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();
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.