Method: Osm::FlexiRecord::Data#update
- Defined in:
- lib/osm/flexi_record.rb
#update(api) ⇒ Boolean
Update data in OSM
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/osm/flexi_record.rb', line 284 def update(api) raise Osm::ObjectIsInvalid, 'data is invalid' unless valid? require_ability_to(api, :write, :flexi, flexi_record.section_id) term_id = Osm::Term.get_current_term_for_section(api, flexi_record.section_id).id updated = true editable_fields = flexi_record.get_columns(api).select{ |c| c.editable }.map{ |i| i.id } fields.changes.each do |field, (was,now)| if editable_fields.include?(field) data = api.perform_query("extras.php?action=updateScout", { 'termid' => term_id, 'scoutid' => self.member_id, 'column' => field, 'value' => now, 'sectionid' => flexi_record.section_id, 'extraid' => flexi_record.id, }) if (data.is_a?(Hash) && data['items'].is_a?(Array)) data['items'].each do |item| if item['scoutid'] == member_id.to_s # Find this member from the list of all members updated = false unless item[field] == now end end else updated = false end end end if updated fields.clean_up! # The cached datas for the flexi record will be out of date - remove them cache_delete(api, ['flexi_record_data', flexi_record.id]) end return updated end |