fix revision count and drop observers
This commit is contained in:
parent
518ecc3d4e
commit
b33e9ed28e
12 changed files with 69 additions and 34 deletions
11
app/models/concerns/revision_count.rb
Normal file
11
app/models/concerns/revision_count.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
module RevisionCount
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
after_update :increment_revision
|
||||
end
|
||||
|
||||
def increment_revision
|
||||
conference.update_column(:revision, conference.revision + 1)
|
||||
end
|
||||
end
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
class Conference < ActiveRecord::Base
|
||||
include RevisionCount
|
||||
require 'uri'
|
||||
serialize :events_per_week, Hash
|
||||
# Needed to call 'Conference.with_role' in /models/ability.rb
|
||||
|
|
@ -734,6 +735,15 @@ class Conference < ActiveRecord::Base
|
|||
(start_hour..(end_hour - 1)).cover?(current_hour) ? current_hour - start_hour : 0
|
||||
end
|
||||
|
||||
##
|
||||
# Return the current conference object to be used in RevisionCount
|
||||
#
|
||||
# ====Returns
|
||||
# * +ActiveRecord+
|
||||
def conference
|
||||
self
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Returns a different html colour for every i and consecutive colors are
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
class Event < ActiveRecord::Base
|
||||
include ActiveRecord::Transitions
|
||||
include RevisionCount
|
||||
has_paper_trail on: [:create, :update], ignore: [:updated_at, :guid, :week], meta: { conference_id: :conference_id }
|
||||
|
||||
acts_as_commentable
|
||||
|
|
@ -251,6 +252,10 @@ class Event < ActiveRecord::Base
|
|||
event_schedules.find_by(schedule_id: program.selected_schedule_id).try(:start_time)
|
||||
end
|
||||
|
||||
def conference
|
||||
program.conference
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
##
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
#
|
||||
# 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, :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
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
class Room < ActiveRecord::Base
|
||||
include RevisionCount
|
||||
belongs_to :venue
|
||||
has_many :event_schedules, dependent: :destroy
|
||||
|
||||
|
|
@ -10,6 +11,10 @@ class Room < ActiveRecord::Base
|
|||
|
||||
validates :size, numericality: { only_integer: true, greater_than: 0 }, allow_nil: true
|
||||
|
||||
def conference
|
||||
venue.conference
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def generate_guid
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
class Track < ActiveRecord::Base
|
||||
include RevisionCount
|
||||
belongs_to :program
|
||||
has_many :events, dependent: :nullify
|
||||
|
||||
|
|
@ -16,6 +17,10 @@ class Track < ActiveRecord::Base
|
|||
|
||||
before_validation :capitalize_color
|
||||
|
||||
def conference
|
||||
program.conference
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def generate_guid
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue