Merge pull request #10324 from tchak/fix-commune-task
chore(task): backfill commune code from name task
This commit is contained in:
commit
f26a91b9b8
1 changed files with 28 additions and 0 deletions
|
@ -0,0 +1,28 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Maintenance
|
||||
class BackfillCommuneCodeFromNameTask < MaintenanceTasks::Task
|
||||
attribute :champ_ids, :string
|
||||
validates :champ_ids, presence: true
|
||||
|
||||
def collection
|
||||
Champ.where(id: champ_ids.split(',').map(&:strip).map(&:to_i))
|
||||
end
|
||||
|
||||
def process(champ)
|
||||
return if champ.type != "Champs::CommuneChamp"
|
||||
return if champ.external_id.present?
|
||||
return if champ.value.blank?
|
||||
|
||||
data = champ.data
|
||||
return if data.blank?
|
||||
return if data['code_departement'].blank?
|
||||
|
||||
external_id = APIGeoService.commune_code(data['code_departement'], champ.value)
|
||||
|
||||
if external_id.present?
|
||||
champ.update(external_id:)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue