Code cleanup.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10842 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-11-18 16:01:07 +00:00
parent 46d27348fd
commit f36b3fff60
2 changed files with 17 additions and 11 deletions

View File

@ -141,15 +141,6 @@ class WikiController < ApplicationController
end end
content_params ||= {} content_params ||= {}
if !@page.new_record? && content_params.present? && @content.text == content_params[:text]
attachments = Attachment.attach_files(@page, params[:attachments])
render_attachment_warning_if_needed(@page)
# don't save content if text wasn't changed
@page.save
redirect_to :action => 'show', :project_id => @project, :id => @page.title
return
end
@content.comments = content_params[:comments] @content.comments = content_params[:comments]
@text = content_params[:text] @text = content_params[:text]
if params[:section].present? && Redmine::WikiFormatting.supports_section_edit? if params[:section].present? && Redmine::WikiFormatting.supports_section_edit?
@ -161,8 +152,8 @@ class WikiController < ApplicationController
@content.text = @text @content.text = @text
end end
@content.author = User.current @content.author = User.current
@page.content = @content
if @page.save if @page.save_with_content
attachments = Attachment.attach_files(@page, params[:attachments]) attachments = Attachment.attach_files(@page, params[:attachments])
render_attachment_warning_if_needed(@page) render_attachment_warning_if_needed(@page)
call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page}) call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page})

View File

@ -173,6 +173,21 @@ class WikiPage < ActiveRecord::Base
self.parent = parent_page self.parent = parent_page
end end
# Saves the page and its content if text was changed
def save_with_content
ret = nil
transaction do
if new_record?
# Rails automatically saves associated content
ret = save
else
ret = save && (content.text_changed? ? content.save : true)
end
raise ActiveRecord::Rollback unless ret
end
ret
end
protected protected
def validate_parent_title def validate_parent_title