Class: BigbluebuttonRecording

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActiveModel::ForbiddenAttributesProtection
Defined in:
app/models/bigbluebutton_recording.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.sync(server, recordings, full_sync = false) ⇒ Object

Syncs the recordings in the db with the array of recordings in ‘recordings’, as received from BigBlueButtonApi#get_recordings. Will add new recordings that are not in the db yet and update the ones that already are (matching by ‘recordid’). Will NOT delete recordings from the db if they are not in the array but instead mark them as unavailable. ‘server’ is the BigbluebuttonServer object from which the recordings were fetched.

TODO: catch exceptions on creating/updating recordings



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/models/bigbluebutton_recording.rb', line 44

def self.sync(server, recordings, full_sync=false)
  recordings.each do |rec|
    rec_obj = BigbluebuttonRecording.find_by_recordid(rec[:recordID])
    rec_data = adapt_recording_hash(rec)
    BigbluebuttonRecording.transaction do
      if rec_obj
        logger.info "Sync recordings: updating recording #{rec_obj.inspect}"
        logger.debug "Sync recordings: recording data #{rec_data.inspect}"
        self.update_recording(server, rec_obj, rec_data)
      else
        logger.info "Sync recordings: creating recording"
        logger.debug "Sync recordings: recording data #{rec_data.inspect}"
        self.create_recording(server, rec_data)
      end
    end
  end

  # set as unavailable the recordings that are not in 'recordings', but
  # only in a full synchronization process, which means that the recordings
  # in `recordings` are *all* available in `server`, not a subset.
  if full_sync
    recordIDs = recordings.map{ |rec| rec[:recordID] }
    if recordIDs.length <= 0 # empty response
      BigbluebuttonRecording.
        where(available: true, server: server).
        update_all(available: false)
    else
      BigbluebuttonRecording.
        where(available: true, server: server).
        where.not(recordid: recordIDs).
        update_all(available: false)
    end
  end
end

Instance Method Details

#default_playback_formatObject



30
31
32
33
# File 'app/models/bigbluebutton_recording.rb', line 30

def default_playback_format
  playback_formats.joins(:playback_type)
    .where("bigbluebutton_playback_types.default = ?", true).first
end

#to_paramObject



26
27
28
# File 'app/models/bigbluebutton_recording.rb', line 26

def to_param
  self.recordid
end