2024-03-06 19:03:30 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Maintenance
|
|
|
|
class UpdateZonesTask < MaintenanceTasks::Task
|
2024-09-30 09:26:46 +02:00
|
|
|
# Synchronise les zones en base à partir du fichier de config zones.yml
|
|
|
|
# 2024-05-27-01 PR #10077
|
2024-03-06 19:03:30 +01:00
|
|
|
def collection
|
|
|
|
config = Psych.safe_load(Rails.root.join("config", "zones.yml").read)
|
|
|
|
config['ministeres']
|
|
|
|
end
|
|
|
|
|
|
|
|
def process(ministere)
|
|
|
|
acronym = ministere.keys.first
|
|
|
|
zone = Zone.find_or_create_by!(acronym: acronym)
|
|
|
|
labels_a = ministere['labels']
|
|
|
|
labels_a.each do |label_h|
|
|
|
|
designated_on = label_h.keys.first
|
|
|
|
label = zone.labels.find_or_initialize_by(designated_on: designated_on)
|
|
|
|
label.update(name: label_h[designated_on])
|
|
|
|
end
|
|
|
|
zone.update(tchap_hs: ministere['tchap_hs']) if ministere['tchap_hs']
|
|
|
|
end
|
|
|
|
|
|
|
|
def count
|
|
|
|
collection.length
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|