From 3cc088e96574f26a3376b6bc7c30bdfbc3f7e1a1 Mon Sep 17 00:00:00 2001 From: maatinito <15379878+maatinito@users.noreply.github.com> Date: Thu, 2 May 2019 13:22:06 -1000 Subject: [PATCH] Obsolete tasks that triggers errors on a fresh database 20180913161001_add_path_to_procedures.rake NoMethodError: undefined method `procedure_path' for # 20181009130216_restore_deleted_dossiers.rake ActiveRecord::RecordNotFound: Couldn't find Procedure with 'id'=4860 20181010102500_remove_invite_gestionnaires.rake NameError: uninitialized constant InviteGestionnaire --- ...20180913161001_add_path_to_procedures.rake | 32 --- ...181009130216_restore_deleted_dossiers.rake | 209 ------------------ ...010102500_remove_invite_gestionnaires.rake | 10 - 3 files changed, 251 deletions(-) delete mode 100644 lib/tasks/deployment/20180913161001_add_path_to_procedures.rake delete mode 100644 lib/tasks/deployment/20181009130216_restore_deleted_dossiers.rake delete mode 100644 lib/tasks/deployment/20181010102500_remove_invite_gestionnaires.rake diff --git a/lib/tasks/deployment/20180913161001_add_path_to_procedures.rake b/lib/tasks/deployment/20180913161001_add_path_to_procedures.rake deleted file mode 100644 index 351cd9224..000000000 --- a/lib/tasks/deployment/20180913161001_add_path_to_procedures.rake +++ /dev/null @@ -1,32 +0,0 @@ -namespace :after_party do - desc 'Deployment task: add_path_to_procedures' - task add_path_to_procedures: :environment do - puts "Running deploy task 'add_path_to_procedures'" - - def print_procedure(procedure) - puts "#{procedure.id}##{procedure.path} - #{procedure.errors.full_messages}" - end - - puts "Démarches publiées :" - Procedure.publiees.where(path: nil).find_each do |procedure| - procedure.path = procedure.path - if !procedure.save - print_procedure(procedure) - end - end - - puts "Démarches archivées :" - Procedure.archivees.where(path: nil).find_each do |procedure| - if procedure.procedure_path.present? - procedure.path = procedure.path - if !procedure.save - print_procedure(procedure) - end - end - end - - # Update task as completed. If you remove the line below, the task will - # run with every deploy (or every time you call after_party:run). - AfterParty::TaskRecord.create version: '20180913161001' - end -end diff --git a/lib/tasks/deployment/20181009130216_restore_deleted_dossiers.rake b/lib/tasks/deployment/20181009130216_restore_deleted_dossiers.rake deleted file mode 100644 index 387d5cf99..000000000 --- a/lib/tasks/deployment/20181009130216_restore_deleted_dossiers.rake +++ /dev/null @@ -1,209 +0,0 @@ -require Rails.root.join("lib", "tasks", "task_helper") - -namespace :after_party do - desc 'Deployment task: restore_deleted_dossiers' - task restore_deleted_dossiers: :environment do - Class.new do - def run - rake_puts "Running deploy task 'restore_deleted_dossiers'" - restore_candidats_libres_deleted_dossiers - restore_neph_deleted_dossiers - AfterParty::TaskRecord.create version: '20181009130216' - end - - def restore_candidats_libres_deleted_dossiers - mapping = Class.new(Tasks::DossierProcedureMigrator::ChampMapping) do - def setup_mapping - champ_opts = { - 16 => { - source_overrides: { 'libelle' => 'Adresse postale du candidat' }, - destination_overrides: { 'libelle' => 'Adresse postale complète du candidat' } - } - } - (0..23).each do |i| - map_source_to_destination_champ(i, i, **(champ_opts[i] || {})) - end - end - end - - private_mapping = Class.new(Tasks::DossierProcedureMigrator::ChampMapping) do - def setup_mapping - compute_destination_champ( - TypeDeChamp.new( - type_champ: 'datetime', - order_place: 0, - libelle: 'Date et heure de convocation', - mandatory: false - ) - ) do |d, target_tdc| - target_tdc.champ.create(dossier: d) - end - compute_destination_champ( - TypeDeChamp.new( - type_champ: 'text', - order_place: 1, - libelle: 'Lieu de convocation', - mandatory: false - ) - ) do |d, target_tdc| - target_tdc.champ.create(dossier: d) - end - compute_destination_champ( - TypeDeChamp.new( - type_champ: 'address', - order_place: 2, - libelle: 'Adresse centre examen', - mandatory: false - ) - ) do |d, target_tdc| - target_tdc.champ.create(dossier: d) - end - end - end - - pj_mapping = Class.new(Tasks::DossierProcedureMigrator::PieceJustificativeMapping) do - def setup_mapping - (0..3).each do |i| - map_source_to_destination_pj(i, i + 2) - end - leave_destination_pj_blank( - TypeDePieceJustificative.new( - order_place: 0, - libelle: "Télécharger la Charte de l'accompagnateur" - ) - ) - leave_destination_pj_blank( - TypeDePieceJustificative.new( - order_place: 1, - libelle: "Télécharger l'attestation d'assurance" - ) - ) - end - end - - restore_deleted_dossiers(4860, 8603, mapping, private_mapping, pj_mapping) - end - - def restore_neph_deleted_dossiers - mapping = Class.new(Tasks::DossierProcedureMigrator::ChampMapping) do - def can_migrate?(dossier) - !(dossier.termine? || - dossier.champs.joins(:type_de_champ).find_by(types_de_champ: { order_place: 3 }).value&.include?('"Demande de duplicata de dossier d\'inscription (suite perte)"')) - end - - def setup_mapping - champ_opts = { - 3 => { - source_overrides: { 'drop_down' => ["", "Demande de réactualisation du numéro NEPH", "Demande de communication du numéro NEPH", "Demande de duplicata de dossier d'inscription (suite perte)", "Demande de correction sur le Fichier National des Permis de conduire"] }, - destination_overrides: { 'drop_down' => ["", "Demande de réactualisation du numéro NEPH", "Demande de communication du numéro NEPH", "Demande de correction sur le Fichier National des Permis de conduire"] } - } - } - (0..14).each do |i| - map_source_to_destination_champ(i, i, **(champ_opts[i] || {})) - end - (16..22).each do |i| - map_source_to_destination_champ(i, i + 2, **(champ_opts[i] || {})) - end - - discard_source_champ( - TypeDeChamp.new( - type_champ: 'address', - order_place: 15, - libelle: 'Adresse du candidat' - ) - ) - - compute_destination_champ( - TypeDeChamp.new( - type_champ: 'address', - order_place: 15, - libelle: 'Adresse du candidat', - mandatory: true - ) - ) do |d, target_tdc| - value = d.champs.joins(:type_de_champ).find_by(types_de_champ: { order_place: 3 }).value - if !d.brouillon? - value ||= 'non renseigné' - end - target_tdc.champ.create(dossier: d, value: value) - end - - compute_destination_champ( - TypeDeChamp.new( - type_champ: 'address', - order_place: 16, - libelle: 'Code postal', - mandatory: true - ) - ) do |d, target_tdc| - target_tdc.champ.create(dossier: d, value: d.brouillon? ? nil : 'non renseigné') - end - - compute_destination_champ( - TypeDeChamp.new( - type_champ: 'address', - order_place: 17, - libelle: 'Ville', - mandatory: true - ) - ) do |d, target_tdc| - target_tdc.champ.create(dossier: d, value: d.brouillon? ? nil : 'non renseigné') - end - end - end - - private_mapping = Class.new(Tasks::DossierProcedureMigrator::ChampMapping) do - def setup_mapping - (0..2).each do |i| - map_source_to_destination_champ(i, i) - end - end - end - - pj_mapping = Class.new(Tasks::DossierProcedureMigrator::PieceJustificativeMapping) do - def setup_mapping - (0..3).each do |i| - map_source_to_destination_pj(i, i) - end - end - end - - restore_deleted_dossiers(6388, 8770, mapping, private_mapping, pj_mapping) - end - - def restore_deleted_dossiers(deleted_procedure_id, new_procedure_id, champ_mapping, champ_private_mapping, pj_mapping) - source_procedure = Procedure.unscoped.find(deleted_procedure_id) - destination_procedure = Procedure.find(new_procedure_id) - - deleted_dossiers = Dossier.unscoped - .where(procedure_id: deleted_procedure_id) - .where('dossiers.hidden_at >= ?', source_procedure.hidden_at) - - deleted_dossier_ids = deleted_dossiers.pluck(:id).to_a - deleted_dossiers.update_all(hidden_at: nil) - - source_procedure - .update_columns( - hidden_at: nil, - archived_at: source_procedure.hidden_at, - aasm_state: :archivee - ) - - migrator = Tasks::DossierProcedureMigrator.new(source_procedure, destination_procedure, champ_mapping, champ_private_mapping, pj_mapping) do |dossier| - DossierMailer.notify_undelete_to_user(dossier).deliver_later - end - migrator.check_consistency - migrator.migrate_dossiers - - source_procedure.dossiers.where(id: deleted_dossier_ids).find_each do |dossier| - if dossier.termine? - DossierMailer.notify_undelete_to_user(dossier).deliver_later - else - rake_puts "Dossier #{dossier.id} non migré\n" - DossierMailer.notify_unmigrated_to_user(dossier, destination_procedure).deliver_later - end - end - end - end.new.run - end -end diff --git a/lib/tasks/deployment/20181010102500_remove_invite_gestionnaires.rake b/lib/tasks/deployment/20181010102500_remove_invite_gestionnaires.rake deleted file mode 100644 index fbbce4a15..000000000 --- a/lib/tasks/deployment/20181010102500_remove_invite_gestionnaires.rake +++ /dev/null @@ -1,10 +0,0 @@ -namespace :after_party do - desc 'Deployment task: remove_invite_gestionnaires' - task remove_invite_gestionnaires: :environment do - InviteGestionnaire.destroy_all - - # Update task as completed. If you remove the line below, the task will - # run with every deploy (or every time you call after_party:run). - AfterParty::TaskRecord.create version: '20181010102500' - end -end