From 52b3877b7045bc5d4840f09ef10071154c3e528e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 3 Nov 2014 15:31:11 +0100 Subject: [PATCH] FIX: don't create a new revision when there was an error while saving the post and/or topic --- lib/post_destroyer.rb | 6 ------ lib/post_revisor.rb | 20 +++++++++----------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/lib/post_destroyer.rb b/lib/post_destroyer.rb index 283573955..9bba2444d 100644 --- a/lib/post_destroyer.rb +++ b/lib/post_destroyer.rb @@ -101,9 +101,6 @@ class PostDestroyer @post.update_flagged_posts_count @post.topic_links.each(&:destroy) end - - # covered by PostRevisor - # @post.publish_change_to_clients! :revised end def user_recovered @@ -113,9 +110,6 @@ class PostDestroyer @post.revise(@user, { raw: @post.revisions.last.modifications["raw"][0] }, force_new_version: true) @post.update_flagged_posts_count end - - # covered by PostRevisor - # @post.publish_change_to_clients! :revised end diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb index e100f4df0..cb616389b 100644 --- a/lib/post_revisor.rb +++ b/lib/post_revisor.rb @@ -67,7 +67,7 @@ class PostRevisor publish_changes grant_badge - @post_successfully_saved && @topic_successfully_saved + successfully_saved_post_and_topic end def cleanup_whitespaces(raw) @@ -93,11 +93,7 @@ class PostRevisor end def revise_post - if should_create_new_version? - revise_and_create_new_version - else - revise - end + should_create_new_version? ? revise_and_create_new_version : revise end def should_create_new_version? @@ -178,11 +174,9 @@ class PostRevisor end def create_or_update_revision - if @version_changed - create_revision - else - update_revision - end + # don't create an empty revision if something failed + return unless successfully_saved_post_and_topic + @version_changed ? create_revision : update_revision end def create_revision @@ -305,4 +299,8 @@ class PostRevisor BadgeGranter.queue_badge_grant(Badge::Trigger::PostRevision, post: @post) end + def successfully_saved_post_and_topic + @post_successfully_saved && @topic_successfully_saved + end + end