From e894f895d42c10fb2f21c3643d3c034d8ee1888e Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Fri, 7 Sep 2018 00:31:45 +0530 Subject: [PATCH] DEV: Extract dates before post_process_cooked event --- plugins/discourse-local-dates/plugin.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/discourse-local-dates/plugin.rb b/plugins/discourse-local-dates/plugin.rb index ec0b902e7a9..cb243194d77 100644 --- a/plugins/discourse-local-dates/plugin.rb +++ b/plugins/discourse-local-dates/plugin.rb @@ -23,7 +23,7 @@ after_initialize do register_post_custom_field_type(DiscourseLocalDates::POST_CUSTOM_FIELD, :json) - on(:post_process_cooked) do |doc, post| + on(:before_post_process_cooked) do |doc, post| dates = doc.css('span.discourse-local-date').map do |cooked_date| date = {} cooked_date.attributes.values.each do |attribute| @@ -39,8 +39,9 @@ after_initialize do if dates.present? post.custom_fields[DiscourseLocalDates::POST_CUSTOM_FIELD] = dates.to_json post.save_custom_fields - elsif post.custom_fields[DiscourseLocalDates::POST_CUSTOM_FIELD].present? - PostCustomField.where(post_id: post.id, name: DiscourseLocalDates::POST_CUSTOM_FIELD).destroy_all + elsif !post.custom_fields[DiscourseLocalDates::POST_CUSTOM_FIELD].nil? + post.custom_fields.delete(DiscourseLocalDates::POST_CUSTOM_FIELD) + post.save_custom_fields end end