Bulk topic timers

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.

2 лайка

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?

1 лайк

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.

2 лайка

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?

3 лайка

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.

4 лайка

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…

1 лайк

This is a pretty unique request, why not consume the api, my feeling is that your own custom sword here will fit way better

4 лайка

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 есть шанс, что вы поделитесь тем, что сделали для достижения этого?

К сожалению, я не сделал никаких заметок :innocent:

Отказ от ответственности: Пожалуйста, выполняйте описанные действия только в том случае, если вы понимаете, что предлагаю, у вас есть резервная копия вашего экземпляра Discourse и вы знаете, как её применить. Я не тестировал это самостоятельно, поэтому могут потребоваться некоторые корректировки.

1. Получите соответствующие ID тем

Этот запрос вернёт ID всех тем из категории с ID 11, которые не удалены и не закрыты.

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

Сначала протестируйте это на одной теме. Надеюсь, это поможет!

2 лайка