diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-10-21 04:43:15 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-10-21 04:43:15 +0000 |
commit | 9796d18609334eaad05188617217f2405a47a645 (patch) | |
tree | 738c1a31646f87f541e2403455611895b917a2d5 /app/models | |
parent | f09be683232748ba649de6b3c1b62f901d9247b8 (diff) | |
download | redmine-9796d18609334eaad05188617217f2405a47a645.tar.gz redmine-9796d18609334eaad05188617217f2405a47a645.zip |
Handle deleted wiki page versions (#10852).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10684 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/wiki_content.rb | 16 | ||||
-rw-r--r-- | app/models/wiki_page.rb | 9 |
2 files changed, 17 insertions, 8 deletions
diff --git a/app/models/wiki_content.rb b/app/models/wiki_content.rb index ac7459826..ec1cd8234 100644 --- a/app/models/wiki_content.rb +++ b/app/models/wiki_content.rb @@ -115,10 +115,18 @@ class WikiContent < ActiveRecord::Base # Returns the previous version or nil def previous - @previous ||= WikiContent::Version.find(:first, - :order => 'version DESC', - :include => :author, - :conditions => ["wiki_content_id = ? AND version < ?", wiki_content_id, version]) + @previous ||= WikiContent::Version. + reorder('version DESC'). + includes(:author). + where("wiki_content_id = ? AND version < ?", wiki_content_id, version).first + end + + # Returns the next version or nil + def next + @next ||= WikiContent::Version. + reorder('version ASC'). + includes(:author). + where("wiki_content_id = ? AND version > ?", wiki_content_id, version).first end end end diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index 2f7803f2a..37d6cf5a4 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -111,11 +111,12 @@ class WikiPage < ActiveRecord::Base def diff(version_to=nil, version_from=nil) version_to = version_to ? version_to.to_i : self.content.version - version_from = version_from ? version_from.to_i : version_to - 1 - version_to, version_from = version_from, version_to unless version_from < version_to - content_to = content.versions.find_by_version(version_to) - content_from = content.versions.find_by_version(version_from) + content_from = version_from ? content.versions.find_by_version(version_from.to_i) : content_to.previous + + if content_from.version > content_to.version + content_to, content_from = content_from, content_to + end (content_to && content_from) ? WikiDiff.new(content_to, content_from) : nil end |