For adding topic timers, e.g., close topic 1 month after last update, it would be great to have a bulk option. This would allow for adding topic timers to multiple topics at once, without going into each individual topic.
Interesting idea. Are you referring to this modal?
If so, an edge cases to consider: What happens if there’s already a topic timer on one (or more) of the selected topics?
Yes, exactly this modal.
I’d find it natural to have the same behavior as if the set topic timer action is performed again on a topic that already has one, i.e., overwrite the existing timer.
May I ask why the “Auto-close topic hours” setting on the category isn’t enough?
Are you adding these timers on topics spanning multiple categories?
Absolutely. I’ve added this setting (720 hours and ticked Don’t close until the last post in the topic is at least this old) and it seems to affect only newly added topics, not those that are currently in this category.
I wanted to bulk add the topic timer to the topics that already existed in the category.
I thought we had a rails command to apply the category setting retroactively too all topics within the category, but I’m failing to find it right now. I’ll keep looking…
This is a pretty unique request, why not consume the api, my feeling is that your own custom sword here will fit way better
Thanks for the suggestion.
I’ve went with a combination of database queries to identify the relevant topic IDs and requests to the timer API.
我刚发现这个话题,也在寻找相同的功能。
有人能分享一下我该如何将计时器应用到某个类别下的所有话题吗?我已经创建了数百个文档话题,刚刚才发现这个功能,想追溯性地应用它。
如果仍然无法通过前端操作,您能提供一些关于如何通过 API 实现的指导吗?我对它还不太熟悉。
谢谢!
@fhe 你能分享一下你是怎么做到这一点的吗?
抱歉,我没有做任何笔记 ![]()
免责声明: 只有当你理解我提出的建议,并且有 Discourse 实例的备份并知道如何应用它时,才请执行任何操作。我没有亲自测试过,所以可能需要一些调整。
1. 获取相关的帖子 ID
这将获取 ID 为 11 的类别中所有未删除且未关闭的帖子 ID。
SELECT id FROM topics WHERE category_id = 11 AND deleted_at IS NULL AND closed = FALSE ORDER BY id
假设结果是 3, 6, 12, 24
2. 创建帖子计时器
接下来,在你的容器中进入 rails 控制台,并使用类似以下的方法:
auto_close_hours = 720
topic_ids = [3,6,12,24]
Topic.where(id: topic_ids).find_each do |topic|
topic.set_or_create_timer(
TopicTimer.types[:close],
auto_close_hours,
based_on_last_post: true
)
MessageBus.publish("/topic/#{topic.id}", reload_topic: true)
end
请先用一个帖子进行测试,希望这有帮助!
