exec_sql is deprecated use db exec instead

exec_sql is deprecated use db exec instead

From ffd4bd1a4a04b9ff443546ecec18740125c7d1fd Mon Sep 17 00:00:00 2001
From: Sam <sam.saffron@gmail.com>
Date: Thu, 21 Jun 2018 12:22:04 +1000
Subject: [PATCH] exec_sql is deprecated use db exec instead


diff --git a/lib/topic_assigner.rb b/lib/topic_assigner.rb
index d02da1a..bf11938 100644
--- a/lib/topic_assigner.rb
+++ b/lib/topic_assigner.rb
@@ -85,14 +85,25 @@ SQL
   end
 
   def self.is_last_staff_post?(post)
-    Post.exec_sql("SELECT 1 FROM posts p
-                   JOIN users u ON u.id = p.user_id AND (moderator OR admin)
-                   WHERE p.deleted_at IS NULL AND p.topic_id = :topic_id
-                   having max(post_number) = :post_number
-                  ",
-                   topic_id: post.topic_id,
-                   post_number: post.post_number
-                 ).to_a.length == 1
+    sql = <<~SQL
+      SELECT 1 FROM posts p
+       JOIN users u ON u.id = p.user_id AND (moderator OR admin)
+       WHERE p.deleted_at IS NULL AND p.topic_id = :topic_id
+       having max(post_number) = :post_number
+
+    SQL
+
+    args = {
+      topic_id: post.topic_id,
+      post_number: post.post_number
+    }
+
+    # TODO post 2.1 release remove
+    if defined?(DB)
+      DB.exec(sql, args) == 1
+    else
+      Post.exec_sql(sql, args).to_a.length == 1
+    end
   end
 
   def self.mentioned_staff(post)

GitHub

1 Like