You are here

function devel_rebuild_node_comment_statistics in Devel 5

Same name and namespace in other branches
  1. 6 devel.module \devel_rebuild_node_comment_statistics()
  2. 7 devel.module \devel_rebuild_node_comment_statistics()

Update node_comment_statistics table for nodes with comments. TODO: if 2 comments have exact same timestamp, the function can get wrong uid and name fields. Handles when comment timestamps have been manually set in admin

Return value

void

1 call to devel_rebuild_node_comment_statistics()
devel_rebuild_node_comment_statistics_page in ./devel.module
Menu callback. Rebuild node _comment_stats table.

File

./devel.module, line 1484

Code

function devel_rebuild_node_comment_statistics() {

  // Empty table
  $sql = "DELETE FROM {node_comment_statistics}";
  db_query($sql);
  $sql = "INSERT INTO {node_comment_statistics} (nid, last_comment_timestamp, last_comment_name, last_comment_uid, comment_count) (select nid, c.timestamp, name, uid, comment_count FROM {comments} c INNER JOIN (SELECT MAX(timestamp) AS timestamp, COUNT(*) AS comment_count FROM {comments} WHERE status=%d GROUP BY nid) as c2 ON c.timestamp=c2.timestamp)";
  db_query($sql, COMMENT_PUBLISHED);

  // Insert 0 count records into the node_comment_statistics for nodes that are missing. See comment_enable()
  db_query_temporary("SELECT n.nid, n.changed, n.uid FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE c.comment_count IS NULL", 'missing_nids');
  db_query("INSERT INTO {node_comment_statistics} (nid, last_comment_timestamp, last_comment_name, last_comment_uid, comment_count) SELECT n.nid, n.changed, NULL, n.uid, 0 FROM missing_nids n");
}