In a discussion titled ‘Auto-close old topics from a migrated forum’, user rodrigofarcas asked how to close a batch of old topics (older than 30 days) after migrating to Discourse, noting that standard auto-close settings do not affect migrated content. While riking suggested using the Bulk Actions menu to close topics manually, sanderteamspywarefri highlighted that this approach is impractical for large datasets, citing 24,000 topics and errors when closing more than 50 at a time.
zogstrip recommended using the Rails console for a more efficient solution. They provided a specific command to SSH into the server and execute a script that automatically closes all topics created before a specific date 10. This method was successfully adopted by the server administrator, saving the user from thousands of manual clicks 11. The user expressed immense gratitude, noting the script ran for a full day and night to resolve the issue 12.
We migrated to Discourse from another forum software, and I want to close a batch of old topics at once.
I’ve tried using the forum setting for auto-close:
But this seems not to be affecting migrated old topics, as they are still open. How can I achieve this? (want to close all topics which are older than 720 hours=30 days)
Click the “menu” icon next to the Topic column header, select the topics to close, click the wrench in the upper right, and select “Close Topics” in the Bulk Actions menu.
cd /var/discourse
./launcher enter app
rails c
Topic.where(closed: false).where("created_at < '2015-01-01'").find_each do |topic|
topic.update_status("closed", true, Discourse.system_user)
end
And you should have all the topics created before January 1st 2015 closed