From f12315075fc5780c68093610295ace7ae2c4ac78 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 26 May 2007 17:22:27 +0000 Subject: [PATCH] Optimistic locking added for wiki edits. git-svn-id: http://redmine.rubyforge.org/svn/trunk@545 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/wiki_controller.rb | 8 ++++++-- app/models/wiki_content.rb | 1 + app/views/wiki/edit.rhtml | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index d8f23cfd1..f85c719bc 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -60,14 +60,18 @@ class WikiController < ApplicationController redirect_to :action => 'index', :id => @project, :page => @page.title return end - @content.text = params[:content][:text] - @content.comments = params[:content][:comments] + #@content.text = params[:content][:text] + #@content.comments = params[:content][:comments] + @content.attributes = params[:content] @content.author = logged_in_user # if page is new @page.save will also save content, but not if page isn't a new record if (@page.new_record? ? @page.save : @content.save) redirect_to :action => 'index', :id => @project, :page => @page.title end end + rescue ActiveRecord::StaleObjectError + # Optimistic locking exception + flash[:notice] = l(:notice_locking_conflict) end # show page history diff --git a/app/models/wiki_content.rb b/app/models/wiki_content.rb index b0382cfaf..5b2e7c34e 100644 --- a/app/models/wiki_content.rb +++ b/app/models/wiki_content.rb @@ -18,6 +18,7 @@ require 'zlib' class WikiContent < ActiveRecord::Base + set_locking_column :version belongs_to :page, :class_name => 'WikiPage', :foreign_key => 'page_id' belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' validates_presence_of :text diff --git a/app/views/wiki/edit.rhtml b/app/views/wiki/edit.rhtml index 1c0139e73..43f2ba5fa 100644 --- a/app/views/wiki/edit.rhtml +++ b/app/views/wiki/edit.rhtml @@ -5,6 +5,7 @@

<%= @page.pretty_title %>

<% form_for :content, @content, :url => {:action => 'edit', :page => @page.title}, :html => {:id => 'wiki_form'} do |f| %> +<%= f.hidden_field :version %> <%= error_messages_for 'content' %>
<%= l(:setting_text_formatting) %>: