# Bulk topic timers

**URL:** https://meta.discourse.org/t/bulk-topic-timers/104941
**Category:** Feature
**Tags:** topic-timers
**Created:** [12월 23, 2018, 10:14오전 UTC](https://meta.discourse.org/t/bulk-topic-timers/104941 "2018-12-23T10:14:30Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![fhe](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fhe/32/113345_2.png) [@fhe](https://meta.discourse.org/u/fhe)
#### Post date: [12월 23, 2018, 10:14오전 UTC](https://meta.discourse.org/t/bulk-topic-timers/104941/1 "2018-12-23T10:14:30Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [12월 23, 2018, 3:25오후 UTC](https://meta.discourse.org/t/bulk-topic-timers/104941/2 "2018-12-23T15:25:23Z")

</div>

Interesting idea. Are you referring to this modal?

 ![image](https://global.discourse-cdn.com/meta/original/3X/f/e/fef9e9a7bba06c866dd0a1ee563fdf338c808d8d.png)

If so, an edge cases to consider: What happens if there’s already a topic timer on one (or more) of the selected topics?

---

<div class="post-metadata">

### Author: ![fhe](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fhe/32/113345_2.png) [@fhe](https://meta.discourse.org/u/fhe)
#### Post date: [12월 23, 2018, 4:28오후 UTC](https://meta.discourse.org/t/bulk-topic-timers/104941/3 "2018-12-23T16:28:31Z")

</div>

> [@jomaxro](#):
>
> Are you referring to this modal?

Yes, exactly this modal.

> [@jomaxro](#):
>
> What happens if there’s already a topic timer on one (or more) of the selected topics?

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.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [12월 23, 2018, 4:42오후 UTC](https://meta.discourse.org/t/bulk-topic-timers/104941/5 "2018-12-23T16:42:33Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![fhe](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fhe/32/113345_2.png) [@fhe](https://meta.discourse.org/u/fhe)
#### Post date: [12월 23, 2018, 4:53오후 UTC](https://meta.discourse.org/t/bulk-topic-timers/104941/6 "2018-12-23T16:53:42Z")

</div>

> [@zogstrip](#):
>
> May I ask why the “ `Auto-close topic hours` ” setting on the category isn’t enough?

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.

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [12월 23, 2018, 5:13오후 UTC](https://meta.discourse.org/t/bulk-topic-timers/104941/7 "2018-12-23T17:13:09Z")

</div>

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…

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [12월 24, 2018, 3:46오후 UTC](https://meta.discourse.org/t/bulk-topic-timers/104941/10 "2018-12-24T15:46:07Z")

</div>

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

---

<div class="post-metadata">

### Author: ![fhe](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fhe/32/113345_2.png) [@fhe](https://meta.discourse.org/u/fhe)
#### Post date: [12월 28, 2018, 2:16오후 UTC](https://meta.discourse.org/t/bulk-topic-timers/104941/11 "2018-12-28T14:16:28Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Nick\_Chomey](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nick_chomey/32/215378_2.png) [@Nick\_Chomey](https://meta.discourse.org/u/Nick_Chomey)
#### Post date: [11월 30, 2021, 1:08오전 UTC](https://meta.discourse.org/t/bulk-topic-timers/104941/12 "2021-11-30T01:08:18Z")

</div>

방금 이 주제를 발견했습니다. 같은 기능을 찾고 있었거든요.

카테고리 내 모든 주제에 타이머를 적용하는 방법을 공유해 주실 수 있나요? 이미 수백 개의 문서(Doculation) 주제를 생성해 두었는데, 이 기능을 이제야 알게 되어 소급 적용하고 싶습니다.

여전히 프론트엔드에서 이 기능을 사용할 수 없다면, API를 통해 어떻게 해야 하는지 안내해 주실 수 있을까요? 아직 API에 익숙하지 않아서요.

감사합니다!

---

<div class="post-metadata">

### Author: ![Nick\_Chomey](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nick_chomey/32/215378_2.png) [@Nick\_Chomey](https://meta.discourse.org/u/Nick_Chomey)
#### Post date: [12월 15, 2021, 1:06오후 UTC](https://meta.discourse.org/t/bulk-topic-timers/104941/13 "2021-12-15T13:06:39Z")

</div>

@fhe 이걸 어떻게 구현하셨는지 공유해 주실 수 있을까요?

---

<div class="post-metadata">

### Author: ![fhe](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fhe/32/113345_2.png) [@fhe](https://meta.discourse.org/u/fhe)
#### Post date: [12월 15, 2021, 2:54오후 UTC](https://meta.discourse.org/t/bulk-topic-timers/104941/14 "2021-12-15T14:54:40Z")

</div>

아쉽게도 메모를 하지 않았습니다 😇

> **면책 조항:** 제가 제안하는 내용을 이해하고, 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 콘솔을 실행하고 다음과 같은 코드를 사용하세요.

```Ruby
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

```

먼저 하나의 주제로 테스트해 보시기 바랍니다. 도움이 되길 바랍니다!
