DEV: Extract dates before post_process_cooked event

This commit is contained in:
Vinoth Kannan 2018-09-07 00:31:45 +05:30
parent f0dab5a5e4
commit e894f895d4
1 changed files with 4 additions and 3 deletions

View File

@ -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