Module: Shared::QueryBatchUpdate

Extended by:
ActiveSupport::Concern
Included in:
AssertedDistribution, BiologicalAssociation, CollectingEvent, CollectionObject, FieldOccurrence, Otu, Source::Bibtex, TaxonName
Defined in:
app/models/concerns/shared/query_batch_update.rb

Overview

Facilitate batch updates that use a BatchQueryRequest

Instance Method Summary collapse

Instance Method Details

#query_update(params, response = nil, async_project_id = nil, async_user_id = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/models/concerns/shared/query_batch_update.rb', line 13

def query_update(
  params, response = nil, async_project_id = nil, async_user_id = nil
)
  if async_project_id && Current.project_id.nil?
    Current.project_id = async_project_id
  end
  if async_user_id && Current.user_id.nil?
    Current.user_id = async_user_id
  end

  begin
    update!( params )
    response.updated.push self.id if response
  rescue ActiveRecord::RecordInvalid => e
    return if response.nil?
    response.not_updated.push e.record.id

    response.errors[e.message] = 0 unless response.errors[e.message]

    response.errors[e.message] += 1
  end
end