FIX: under certain conditions, raw would change an cooked remain

when editing a post
This commit is contained in:
Sam 2014-09-04 10:43:57 +10:00
parent 9e41ee4390
commit c6e6d00e2b
1 changed files with 21 additions and 11 deletions

View File

@ -21,21 +21,33 @@ class PostRevisor
@opts = opts
@new_raw = TextCleaner.normalize_whitespaces(new_raw).gsub(/\s+\z/, "")
# TODO this is not in a transaction - dangerous!
return false unless should_revise?
Post.transaction do
@post.acting_user = @editor
Post.transaction do
revise_post
# TODO these callbacks are being called in a transaction
# it is kind of odd, cause the callback is called before_edit
# but the post is already edited at this point
# trouble is that much of the logic of should I edit? is deeper
# down so yanking this in front of the transaction will lead to
# false positives. This system needs a review
plugin_callbacks
update_category_description
update_topic_excerpt
post_process_post
update_topic_word_counts
@post.advance_draft_sequence
end
# WARNING: do not pull this into the transaction, it can fire events in
# sidekiq before the post is done saving leading to corrupt state
post_process_post
update_topic_word_counts
PostAlerter.new.after_save_post(@post)
@post.publish_change_to_clients! :revised
BadgeGranter.queue_badge_grant(Badge::Trigger::PostRevision, post: @post)
@ -73,14 +85,12 @@ class PostRevisor
end
def revise_and_create_new_version
Post.transaction do
@post.version += 1
@post.last_version_at = get_revised_at
update_post
EditRateLimiter.new(@editor).performed! unless @opts[:bypass_rate_limiter] == true
bump_topic unless @opts[:bypass_bump]
end
end
def bump_topic
unless Post.where('post_number > ? and topic_id = ?', @post.post_number, @post.topic_id).exists?