1
0
mirror of synced 2026-08-05 09:46:57 +00:00

DEV: Avoid nil custom fields (#128)

This commit is contained in:
Jarek Radosz
2021-05-05 12:19:00 +02:00
committed by GitHub
parent 8a2fdaf063
commit ce63d80abb
2 changed files with 28 additions and 4 deletions
@@ -0,0 +1,24 @@
# frozen_string_literal: true
class RemoveNilCustomFieldsFromSolved < ActiveRecord::Migration[6.0]
def up
execute <<~SQL
DELETE FROM post_custom_fields
WHERE name = 'is_accepted_answer' AND value IS NULL
SQL
execute <<~SQL
DELETE FROM topic_custom_fields
WHERE name = 'accepted_answer_post_id' AND value IS NULL
SQL
execute <<~SQL
DELETE FROM topic_custom_fields
WHERE name = 'solved_auto_close_topic_timer_id' AND value IS NULL
SQL
end
def down
raise ActiveRecord::IrreversibleMigration
end
end
+4 -4
View File
@@ -83,7 +83,7 @@ SQL
if accepted_id > 0
if p2 = Post.find_by(id: accepted_id)
p2.custom_fields["is_accepted_answer"] = nil
p2.custom_fields.delete("is_accepted_answer")
p2.save!
if defined?(UserAction::SOLVED)
@@ -168,13 +168,13 @@ SQL
topic ||= post.topic
DistributedMutex.synchronize("discourse_solved_toggle_answer_#{topic.id}") do
post.custom_fields["is_accepted_answer"] = nil
topic.custom_fields["accepted_answer_post_id"] = nil
post.custom_fields.delete("is_accepted_answer")
topic.custom_fields.delete("accepted_answer_post_id")
if timer_id = topic.custom_fields[AUTO_CLOSE_TOPIC_TIMER_CUSTOM_FIELD]
topic_timer = TopicTimer.find_by(id: timer_id)
topic_timer.destroy! if topic_timer
topic.custom_fields[AUTO_CLOSE_TOPIC_TIMER_CUSTOM_FIELD] = nil
topic.custom_fields.delete(AUTO_CLOSE_TOPIC_TIMER_CUSTOM_FIELD)
end
topic.save!