function _forum_update_forum_index

7.x forum.module _forum_update_forum_index($nid)

Updates the taxonomy index for a given node.

Parameters

$nid: The ID of the node to update.

6 calls to _forum_update_forum_index()
forum_comment_delete in drupal-7.x/modules/forum/forum.module
Implements hook_comment_delete().
forum_comment_publish in drupal-7.x/modules/forum/forum.module
Implements hook_comment_publish().
forum_comment_unpublish in drupal-7.x/modules/forum/forum.module
Implements hook_comment_unpublish().
forum_comment_update in drupal-7.x/modules/forum/forum.module
Implements hook_comment_update().
forum_field_storage_pre_update in drupal-7.x/modules/forum/forum.module
Implements hook_field_storage_pre_update().

... See full list

File

drupal-7.x/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();
  }
}