Skip to content

Commit

Permalink
fixed optimistic locking with postgresql - added timestamp field to a…
Browse files Browse the repository at this point in the history
…dmin wikipage edit form
  • Loading branch information
mseppae committed Sep 29, 2009
1 parent f7f814e commit 032aec1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
Expand Up @@ -152,7 +152,8 @@ def optimistic_lock
raise t(:'adva.articles.exception.missing_timestamp')
end

if @article.updated_at && (Time.zone.parse(updated_at) != @article.updated_at)
# We parse the timestamp of article too so we can get rid of those microseconds postgresql adds
if @article.updated_at && (Time.zone.parse(updated_at) != Time.zone.parse(@article.updated_at.to_s))
flash[:error] = t(:'adva.articles.flash.optimistic_lock.failure')
render :action => :edit
end
Expand Down
Expand Up @@ -100,13 +100,14 @@ def set_wikipage_param(key, value)

def optimistic_lock
return unless params[:wikipage]

unless updated_at = params[:wikipage].delete(:updated_at)
# TODO raise something more explicit here
raise t(:'adva.wiki.exception.missing_timestamp')
end

if @wikipage.updated_at && (Time.zone.parse(updated_at) != @wikipage.updated_at)

# We parse the timestamp of wikipage too so we can get rid of those microseconds postgresql adds
if @wikipage.updated_at && (Time.zone.parse(updated_at) != Time.zone.parse(@wikipage.updated_at.to_s))
flash[:error] = t(:'adva.wiki.flash.optimistic_lock.failure')
render :action => :edit
end
Expand Down
3 changes: 2 additions & 1 deletion engines/adva_wiki/app/controllers/wiki_controller.rb
Expand Up @@ -154,7 +154,8 @@ def optimistic_lock
raise t(:'adva.wiki.exception.missing_timestamp')
end

if @wikipage.updated_at && (Time.zone.parse(updated_at) != @wikipage.updated_at)
# We parse the timestamp of wikipage too so we can get rid of those microseconds postgresql adds
if @wikipage.updated_at && (Time.zone.parse(updated_at) != Time.zone.parse(@wikipage.updated_at.to_s))
flash[:error] = t(:'adva.wiki.flash.optimistic_lock.failure')
render :action => :edit
end
Expand Down
1 change: 1 addition & 0 deletions engines/adva_wiki/app/views/admin/wikipages/edit.html.erb
@@ -1,6 +1,7 @@
<h2><%= t(:'adva.wikipage.view.edit.header', :title => @wikipage.title) %></h2>

<% split_form_for :wikipage, @wikipage, :url => admin_wikipage_path, :html => {:multipart => true, :method => :put, :id => 'content_form'} do |f| -%>
<%= f.hidden_field :updated_at, :value => @wikipage.updated_at %>
<%= render :partial => "form", :locals => {:f => f} %>
<% save_or_cancel_links(f, :cancel_url => admin_wikipage_path) %>
Expand Down

0 comments on commit 032aec1

Please sign in to comment.