FEATURE: Add a plugin callback when editing a post

FIX: Wrap PostRevisor database work in a transaction
This commit is contained in:
riking 2014-08-28 21:27:40 -07:00
parent b7e8bcda07
commit 24ba7ccfbb
2 changed files with 23 additions and 8 deletions

View File

@ -69,6 +69,7 @@ class PostCreator
setup_topic
setup_post
rollback_if_host_spam_detected
plugin_callbacks
save_post
extract_links
store_unique_post_key
@ -113,7 +114,6 @@ class PostCreator
post.cooked ||= post.cook(post.raw, cooking_options)
post.sort_order = post.post_number
DiscourseEvent.trigger(:before_create_post, post)
post.last_version_at ||= Time.now
end
@ -157,6 +157,11 @@ class PostCreator
end
end
def plugin_callbacks
DiscourseEvent.trigger :before_create_post, @post
DiscourseEvent.trigger :validate_post, @post
end
def track_latest_on_category
return unless @post && @post.errors.count == 0 && @topic && @topic.category_id

View File

@ -22,13 +22,18 @@ class PostRevisor
@new_raw = TextCleaner.normalize_whitespaces(new_raw).strip
return false unless should_revise?
Post.transaction do
@post.acting_user = @editor
revise_post
plugin_callbacks
update_category_description
update_topic_excerpt
post_process_post
update_topic_word_counts
@post.advance_draft_sequence
end
PostAlerter.new.after_save_post(@post)
publish_revision
BadgeGranter.queue_badge_grant(Badge::Trigger::PostRevision, post: @post)
@ -61,6 +66,11 @@ class PostRevisor
end
end
def plugin_callbacks
DiscourseEvent.trigger :before_edit_post, @post
DiscourseEvent.trigger :validate_post, @post
end
def get_revised_at
@opts[:revised_at] || Time.now
end