mirror of
https://github.com/discourse/discourse.git
synced 2025-06-05 23:15:01 +08:00
FIX: update categories topic_count when converting topic to a PM and vice versa
This commit is contained in:
@ -24,6 +24,7 @@ class TopicConverter
|
||||
@topic.archetype = Archetype.default
|
||||
@topic.save
|
||||
update_user_stats
|
||||
update_category_topic_count_by(1)
|
||||
|
||||
# TODO: Every post in a PRIVATE MESSAGE looks the same: each is a UserAction::NEW_PRIVATE_MESSAGE.
|
||||
# So we need to remove all those user actions and re-log all the posts.
|
||||
@ -46,6 +47,7 @@ class TopicConverter
|
||||
|
||||
def convert_to_private_message
|
||||
Topic.transaction do
|
||||
update_category_topic_count_by(-1)
|
||||
@topic.category_id = nil
|
||||
@topic.archetype = Archetype.private_message
|
||||
add_allowed_users
|
||||
@ -92,4 +94,10 @@ class TopicConverter
|
||||
end
|
||||
end
|
||||
|
||||
def update_category_topic_count_by(num)
|
||||
if @topic.category_id.present?
|
||||
Category.where(['id = ?', @topic.category_id]).update_all("topic_count = topic_count " + (num > 0 ? '+' : '') + "#{num}")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user