Merge pull request #10324 from tchak/fix-commune-task

chore(task): backfill commune code from name task
This commit is contained in:
Paul Chavard 2024-04-15 11:09:52 +00:00 committed by GitHub
commit f26a91b9b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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