From e3cf14016fe0eb1ad1630f4517c5fbc04c36b6e8 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 27 Feb 2017 19:51:50 +0000 Subject: [PATCH] Check discourse version before adding TopicQuery filters --- plugin.rb | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/plugin.rb b/plugin.rb index 845b660..ad75663 100644 --- a/plugin.rb +++ b/plugin.rb @@ -337,25 +337,27 @@ SQL end end - require_dependency 'topic_query' + if Discourse.has_needed_version?(Discourse::VERSION::STRING, '1.8.0.beta6') + require_dependency 'topic_query' - TopicQuery.add_custom_filter(:solved) do |results, topic_query| - if topic_query.options[:solved] == 'true' - results = results.where("topics.id IN ( - SELECT tc.topic_id - FROM topic_custom_fields tc - WHERE tc.name = 'accepted_answer_post_id' AND - tc.value IS NOT NULL - )") - elsif topic_query.options[:solved] == 'false' - results = results.where("topics.id NOT IN ( - SELECT tc.topic_id - FROM topic_custom_fields tc - WHERE tc.name = 'accepted_answer_post_id' AND - tc.value IS NOT NULL - )") + TopicQuery.add_custom_filter(:solved) do |results, topic_query| + if topic_query.options[:solved] == 'true' + results = results.where("topics.id IN ( + SELECT tc.topic_id + FROM topic_custom_fields tc + WHERE tc.name = 'accepted_answer_post_id' AND + tc.value IS NOT NULL + )") + elsif topic_query.options[:solved] == 'false' + results = results.where("topics.id NOT IN ( + SELECT tc.topic_id + FROM topic_custom_fields tc + WHERE tc.name = 'accepted_answer_post_id' AND + tc.value IS NOT NULL + )") + end + results end - results end require_dependency 'topic_list_item_serializer'