DEV: Move the post and topic custom fields into a table

This PR does some preparatory work to prepare for the front-end display
of who marked an answer as solved. It migrates the custom fields from
discourse-solved of Topic and Post to a new table, except "accepted_answer_post_id"

ref: /t/-/95318
This commit is contained in:
Lhc_fl
2024-09-05 17:55:02 +08:00
parent 187b8bf19d
commit 150f7f4a35
9 changed files with 123 additions and 76 deletions
+1 -4
View File
@@ -40,10 +40,7 @@ class DiscourseSolved::BeforeHeadClose
},
}
if accepted_answer =
Post.find_by(
id: topic.custom_fields[::DiscourseSolved::ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD],
)
if accepted_answer = topic.solution&.post
question_json["answerCount"] = 1
question_json[:acceptedAnswer] = {
"@type" => "Answer",
@@ -18,12 +18,7 @@ module DiscourseSolved
def apply_plugin_api
plugin.register_modifier(:assigns_reminder_assigned_topics_query) do |query|
next query if !SiteSetting.ignore_solved_topics_in_assigned_reminder
query.where.not(
id:
TopicCustomField.where(
name: ::DiscourseSolved::ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD,
).pluck(:topic_id),
)
query.where.not(id: DiscourseSolved::Solution.pluck(:topic_id))
end
end
end
+10
View File
@@ -0,0 +1,10 @@
# frozen_string_literal: true
module ::DiscourseSolved
class Solution < ActiveRecord::Base
belongs_to :accepter, foreign_key: :accepter_user_id, class_name: :user
belongs_to :post, foreign_key: :answer_post_id
belongs_to :topic
belongs_to :topic_timer, dependent: :destroy
end
end