function _forum_update_forum_index

_forum_update_forum_index($nid)

Updates the taxonomy index for a given node.

Parameters

$nid: The ID of the node to update.

File

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

Code

function _forum_update_forum_index($nid) {
  $count = db_query('SELECT COUNT(cid) FROM {comment} c INNER JOIN {forum_index} i ON c.nid = i.nid WHERE c.nid = :nid AND c.status = :status', array(
    ':nid' => $nid,
    ':status' => COMMENT_PUBLISHED,
  ))->fetchField();

  if ($count > 0) {
    // Comments exist.
    $last_reply = db_query_range('SELECT cid, name, created, uid FROM {comment} WHERE nid = :nid AND status = :status ORDER BY cid DESC', 0, 1, array(
      ':nid' => $nid,
      ':status' => COMMENT_PUBLISHED,
    ))->fetchObject();
    db_update('forum_index')
      ->fields(array(
        'comment_count' => $count,
        'last_comment_timestamp' => $last_reply->created,
      ))
      ->condition('nid', $nid)
      ->execute();
  }
  else {
    // Comments do not exist.
    $node = db_query('SELECT uid, created FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchObject();
    db_update('forum_index')
      ->fields(array(
        'comment_count' => 0,
        'last_comment_timestamp' => $node->created,
      ))
      ->condition('nid', $nid)
      ->execute();
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!forum!forum.module/function/_forum_update_forum_index/7.x