FIX: plugin backwards compatibility with Discourse 2.4 (#87)

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

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

GitHub sha: 922b4c39

1 Like

This commit appears in #87 which was merged by SamSaffron.