YAFLogo

SURFThru
  • SURFThru
  • 63.8% (Friendly)
  • YAF Forumling Topic Starter
16 years ago
I moved some posts around in the forums and the counts did not change in any of the forums.

Is there a method to recount all the posts in the forums?

Sponsor
Jaben
  • Jaben
  • 100% (Exalted)
  • YAF Developer
16 years ago
cbm
  • cbm
  • 50.6% (Neutral)
  • YAF Forumling
16 years ago
To do this recount, you can just run this simple script in your DB. I did write and use it when I've moved my forum from phpBB to yaf.

This will not only update you forum counters, but also fix any "last post" and "last topic" if broken.


use [your_database]

-- Update users counter
update yaf_User set 
NumPosts = 
(select count(*) from yaf_Message where yaf_Message.UserID = yaf_User.UserID)

-- Update topics counter and last posts
update yaf_Topic set
LastPosted = 
(select top(1) yaf_Message.Posted from yaf_Message where yaf_Message.TopicID = yaf_Topic.TopicID order by Posted desc),
LastMessageID = 
(select top(1) yaf_Message.MessageID from yaf_Message where yaf_Message.TopicID = yaf_Topic.TopicID order by Posted desc),
LastUserID = 
(select top(1) yaf_Message.UserID from yaf_Message where yaf_Message.TopicID = yaf_Topic.TopicID order by Posted desc),
NumPosts = 
(select count(*) from yaf_Message where yaf_Message.TopicID = yaf_Topic.TopicID)

-- Update forums counters and last posts
update yaf_Forum set
LastTopicID = 
(select top(1) yaf_Topic.TopicID from yaf_Topic where yaf_Topic.ForumID = yaf_Forum.ForumID order by yaf_Topic.Posted desc),
LastMessageID = 
(select top(1) yaf_Topic.LastMessageID from yaf_Topic where yaf_Topic.ForumID = yaf_Forum.ForumID order by yaf_Topic.LastPosted desc),
LastUserID = 
(select top(1) yaf_Topic.LastUserID from yaf_Topic where yaf_Topic.ForumID = yaf_Forum.ForumID order by yaf_Topic.LastPosted desc),
NumTopics = 
(select count(*) from yaf_Topic where yaf_Topic.ForumID = yaf_Forum.ForumID),
NumPosts = 
(select sum(NumPosts) from yaf_Topic where yaf_Topic.ForumID = yaf_Forum.ForumID)