Hi,
I have migrated a forum from XenForo to Discourse, now there are many old posts that I would like to close. Is there a way to say “close all topics older than x months”? I have already set this in the category, but it only works for new topics.
Hi,
I have migrated a forum from XenForo to Discourse, now there are many old posts that I would like to close. Is there a way to say “close all topics older than x months”? I have already set this in the category, but it only works for new topics.
You could try using this setting in the Category settings:
I’m not sure if it’ll retroactively close things but it’s worth a shot.
My other thought was to do some advanced filter and a set a Before date:
From there you can use bulk actions on the topics that come up.
You can close topics in bulk with Performing bulk actions as a moderator
But depending on how many topics you want to close, Administrative Bulk Operations may be the better choice.
Yes, there would be something similar linked, how can I narrow it down to one category?
You can find the category ID, then use it as an additional condition in the command. For example, close all open topics in the ‘general’ category that were created prior to September 24th:
cat_id = Category.find_by_slug('general').id
Topic.where(closed: false).where("created_at < '2024-09-24'").where(category_id: cat_id).find_each do |topic|
topic.update_status('closed', true, Discourse.system_user)
end
These types of operations always make me a little nervous. Be sure to create a backup of your database before running them in case something goes wrong. It might also be a good idea to run some kind of preliminary check to make sure that you are operating on the correct data. One way to do that would be to return the count
of topics that the operation will be performed on. For example:
Topic.where(closed: false).where("created_at < '2024-09-24'").where(category_id: cat_id).count
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.