Skip to content

Instantly share code, notes, and snippets.

@BBGuy
Created August 14, 2014 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BBGuy/8c282cefcb72ab8b4cd8 to your computer and use it in GitHub Desktop.
Save BBGuy/8c282cefcb72ab8b4cd8 to your computer and use it in GitHub Desktop.
Sort out Drupal 7: Notice: Undefined property: stdClass::$comment_count in comment_node_page_additions()
drush vset comment_maintain_node_statistics TRUE
SET SQL_SAFE_UPDATES = 0;
TRUNCATE TABLE node_comment_statistics;
INSERT INTO
node_comment_statistics
(
nid,
cid,
last_comment_timestamp,
last_comment_name,
last_comment_uid,
comment_count
)
SELECT
n.nid,
IFNULL(max_node_comment.max_cid,0) AS cid,
IFNULL(last_comment.changed,n.changed) AS last_comment_timestamp,
IFNULL(last_comment.name,null) AS last_comment_name,
IFNULL(last_comment.uid,n.uid) AS last_comment_uid,
IFNULL(comment_count.comment_count,0) AS comment_count
FROM
node AS n
LEFT OUTER JOIN (SELECT nid, COUNT(*) AS comment_count FROM comment WHERE status=1 GROUP BY nid) AS comment_count ON comment_count.nid=n.nid
LEFT OUTER JOIN (SELECT nid, MAX(cid) AS max_cid FROM comment WHERE status=1 GROUP by nid) AS max_node_comment ON max_node_comment.nid=n.nid
LEFT OUTER JOIN (SELECT cid,uid,name,changed FROM comment) AS last_comment ON last_comment.cid=max_node_comment.max_cid
ORDER BY
n.nid;
SET SQL_SAFE_UPDATES = 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment