diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-10-23 18:45:14 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-10-23 18:45:14 +0000 |
commit | 6cccdce06eff37c51b0802ad2b85a71497084523 (patch) | |
tree | 45ff4588eca7da9fbc1f3de364eafa1ff128b672 /app/models/wiki_content.rb | |
parent | 9e7f71080f9230656e8a6981d14576f4b3d40a79 (diff) | |
download | redmine-6cccdce06eff37c51b0802ad2b85a71497084523.tar.gz redmine-6cccdce06eff37c51b0802ad2b85a71497084523.zip |
Ability to delete a version from a wiki page history (#10852).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10705 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/wiki_content.rb')
-rw-r--r-- | app/models/wiki_content.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/app/models/wiki_content.rb b/app/models/wiki_content.rb index ec1cd8234..7c5704902 100644 --- a/app/models/wiki_content.rb +++ b/app/models/wiki_content.rb @@ -73,6 +73,8 @@ class WikiContent < ActiveRecord::Base "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " + "LEFT JOIN #{Project.table_name} ON #{Project.table_name}.id = #{Wiki.table_name}.project_id"} + after_destroy :page_update_after_destroy + def text=(plain) case Setting.wiki_compression when 'gzip' @@ -128,5 +130,18 @@ class WikiContent < ActiveRecord::Base includes(:author). where("wiki_content_id = ? AND version > ?", wiki_content_id, version).first end + + private + + # Updates page's content if the latest version is removed + # or destroys the page if it was the only version + def page_update_after_destroy + latest = page.content.versions.reorder("#{self.class.table_name}.version DESC").first + if latest && page.content.version != latest.version + raise ActiveRecord::Rollback unless page.content.revert_to!(latest) + elsif latest.nil? + raise ActiveRecord::Rollback unless page.destroy + end + end end end |