From 922b4c3907a423a279ff4f5693efcaa11005ff9e Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Mon, 27 Apr 2020 13:01:01 +1000 Subject: [PATCH] FIX: plugin backwards compatibility with Discourse 2.4 (#87) Duration is a new keyword argument on Topic#set_or_create_timer and is not yet available in stable Discourse --- plugin.rb | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/plugin.rb b/plugin.rb index 861a9ac..b6578ff 100644 --- a/plugin.rb +++ b/plugin.rb @@ -123,12 +123,22 @@ SQL auto_close_hours = SiteSetting.solved_topics_auto_close_hours if (auto_close_hours > 0) && !topic.closed - topic_timer = topic.set_or_create_timer( - TopicTimer.types[:close], - nil, - based_on_last_post: true, - duration: auto_close_hours - ) + begin + topic_timer = topic.set_or_create_timer( + TopicTimer.types[:close], + nil, + based_on_last_post: true, + duration: auto_close_hours + ) + rescue ArgumentError + # https://github.com/discourse/discourse/commit/aad12822b7d7c9c6ecd976e23d3a83626c052dce#diff-4d0afa19fa7752955f36089bca420ab4L1135 + # this rescue block can be deleted after discourse stable version > 2.4 + topic_timer = topic.set_or_create_timer( + TopicTimer.types[:close], + auto_close_hours, + based_on_last_post: true + ) + end topic.custom_fields[ AUTO_CLOSE_TOPIC_TIMER_CUSTOM_FIELD