mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
Add 'revision' attribute to Conference, managed by an observer
This commit is contained in:
parent
27017a4823
commit
d648ab7cb5
4 changed files with 34 additions and 1 deletions
26
app/models/revision_observer.rb
Normal file
26
app/models/revision_observer.rb
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#
|
||||
# suseconferenceclient relies on a 'revision' attribute for caching and
|
||||
# doing some calculations.
|
||||
#
|
||||
# It should be incremented after any change in the conference or in any
|
||||
# associated models
|
||||
#
|
||||
# This observer updates the revision column in a non-intrusive way,
|
||||
# preventing validations, callbacks or exceptions to be triggered
|
||||
#
|
||||
# Relying on paper_trail could also be an option, but a 'revision' column
|
||||
# in table 'conferences' looks like a more simple and straightforward solution
|
||||
#
|
||||
class RevisionObserver < ActiveRecord::Observer
|
||||
observe :conference, :event, :room, :social_event, :track
|
||||
|
||||
def after_save(model)
|
||||
begin
|
||||
conference = model.kind_of?(Conference) ? model : model.conference
|
||||
conference.reload.increment(:revision)
|
||||
conference.update_column(:revision, conference.revision)
|
||||
rescue
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -25,6 +25,7 @@ module Osem
|
|||
|
||||
# Activate observers that should always be running.
|
||||
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
||||
config.active_record.observers = :revision_observer
|
||||
|
||||
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
||||
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
||||
|
|
|
|||
5
db/migrate/20130705055128_add_revision_to_conference.rb
Normal file
5
db/migrate/20130705055128_add_revision_to_conference.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class AddRevisionToConference < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :conferences, :revision, :integer
|
||||
end
|
||||
end
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20130626095459) do
|
||||
ActiveRecord::Schema.define(:version => 20130705055128) do
|
||||
|
||||
create_table "call_for_papers", :force => true do |t|
|
||||
t.date "start_date", :null => false
|
||||
|
|
@ -62,6 +62,7 @@ ActiveRecord::Schema.define(:version => 20130626095459) do
|
|||
t.datetime "logo_updated_at"
|
||||
t.boolean "use_dietary_choices", :default => false
|
||||
t.boolean "use_supporter_levels", :default => false
|
||||
t.integer "revision"
|
||||
end
|
||||
|
||||
create_table "dietary_choices", :force => true do |t|
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue