Merge pull request #2718 from riking/plugin-events

FEATURE: Add a plugin callback when editing a post
This commit is contained in:
Robin Ward 2014-09-02 10:46:08 -04:00
commit ab02ef4221
2 changed files with 23 additions and 8 deletions

View File

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

View File

@ -23,13 +23,18 @@ class PostRevisor
# TODO this is not in a transaction - dangerous! # TODO this is not in a transaction - dangerous!
return false unless should_revise? return false unless should_revise?
@post.acting_user = @editor
revise_post Post.transaction do
update_category_description @post.acting_user = @editor
update_topic_excerpt revise_post
post_process_post plugin_callbacks
update_topic_word_counts update_category_description
@post.advance_draft_sequence update_topic_excerpt
post_process_post
update_topic_word_counts
@post.advance_draft_sequence
end
PostAlerter.new.after_save_post(@post) PostAlerter.new.after_save_post(@post)
@post.publish_change_to_clients! :revised @post.publish_change_to_clients! :revised
BadgeGranter.queue_badge_grant(Badge::Trigger::PostRevision, post: @post) BadgeGranter.queue_badge_grant(Badge::Trigger::PostRevision, post: @post)
@ -51,6 +56,11 @@ class PostRevisor
end end
end end
def plugin_callbacks
DiscourseEvent.trigger :before_edit_post, @post
DiscourseEvent.trigger :validate_post, @post
end
def get_revised_at def get_revised_at
@opts[:revised_at] || Time.now @opts[:revised_at] || Time.now
end end