2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-02-01 10:36:21 +01:00
|
|
|
class Migrations::BackfillDossierRepetitionJob < ApplicationJob
|
|
|
|
def perform(dossier_ids)
|
|
|
|
Dossier.where(id: dossier_ids)
|
|
|
|
.includes(:champs, revision: :types_de_champ)
|
|
|
|
.find_each do |dossier|
|
2023-02-01 14:00:10 +01:00
|
|
|
dossier
|
|
|
|
.revision
|
2023-02-01 10:36:21 +01:00
|
|
|
.types_de_champ
|
2023-02-01 14:00:10 +01:00
|
|
|
.filter do |type_de_champ|
|
2024-07-01 15:31:32 +02:00
|
|
|
type_de_champ.type_champ == 'repetition' && dossier.champs.none? { _1.stable_id == type_de_champ.stable_id }
|
2023-02-01 14:00:10 +01:00
|
|
|
end
|
2023-02-01 10:36:21 +01:00
|
|
|
.each do |type_de_champ|
|
2024-07-01 15:31:32 +02:00
|
|
|
dossier.champs << type_de_champ.build_champ
|
2023-02-01 10:36:21 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|