Callback for topic_closed and topic_reopened

I need to run a sidekiq job in these two cases. My original thought was to extend the Topic model with an after_save method, but wondered if there was a better way triggered off of these events. I searched the source code for ways to hook into these but couldn’t see a way. Do these exist and I’m not seeing it?

Turns out that an after_save won’t work. If you check for topic.changed, you won’t see an update to closed. Doesn’t work with a before_save either since it’s changed with a transaction and the callback isn’t called. Has anyone been able to trigger (in any capacity) on these two events? I’d rather not resort to monkey patching it in.

Decided to go ahead and create a PR to add the event.

https://github.com/discourse/discourse/pull/4037

2 Likes