Anonymous avatar Anonymous committed 79dd919

Code cleanup.

Comments (0)

Files changed (2)

app/controllers/wiki_controller.rb

     end
     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]
     @text = content_params[:text]
     if params[:section].present? && Redmine::WikiFormatting.supports_section_edit?
       @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})

app/models/wiki_page.rb

     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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.