Class: BigbluebuttonRecording
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- BigbluebuttonRecording
- Includes:
- ActiveModel::ForbiddenAttributesProtection
- Defined in:
- app/models/bigbluebutton_recording.rb
Class Method Summary collapse
-
.sync(server, recordings) ⇒ Object
Syncs the recordings in the db with the array of recordings in ‘recordings’, as received from BigBlueButtonApi#get_recordings.
Instance Method Summary collapse
Class Method Details
.sync(server, recordings) ⇒ 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
39 40 41 42 43 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 |
# File 'app/models/bigbluebutton_recording.rb', line 39 def self.sync(server, recordings) 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' recordIDs = recordings.map{ |rec| rec[:recordID] } if recordIDs.length <= 0 # empty response BigbluebuttonRecording .where(:available => true) .update_all(:available => false) else BigbluebuttonRecording .where(:available => true) .where("recordid NOT IN (?)", recordIDs) .update_all(:available => false) end end |
Instance Method Details
#to_param ⇒ Object
26 27 28 |
# File 'app/models/bigbluebutton_recording.rb', line 26 def to_param self.recordid end |