From f0aad8c2a8d78e4ad763fb751d43c814587aa3c6 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Wed, 9 Jan 2013 14:01:27 +0000 Subject: [PATCH] Backported r10842 from trunk. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/2.1-stable@11150 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/wiki_controller.rb | 13 ++----------- app/models/wiki_page.rb | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 29d06d2e6..04905d545 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -129,15 +129,6 @@ class WikiController < ApplicationController # don't keep previous comment @content.comments = nil - if !@page.new_record? && params[:content].present? && @content.text == params[:content][: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 = params[:content][:comments] @text = params[:content][:text] if params[:section].present? && Redmine::WikiFormatting.supports_section_edit? @@ -149,8 +140,8 @@ class WikiController < ApplicationController @content.text = @text end @content.author = User.current - @page.content = @content - if @page.save + + if @page.save_with_content attachments = Attachment.attach_files(@page, params[:attachments]) render_attachment_warning_if_needed(@page) call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page}) diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index 2f7803f2a..e30690c9e 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -172,6 +172,21 @@ class WikiPage < ActiveRecord::Base self.parent = parent_page 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 def validate_parent_title