From cf98e28178f0278dc93abee21a46c0e2a2a062d2 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 21 Nov 2018 17:45:10 +0100 Subject: [PATCH] Fix notifications on dossiers with migrated carto --- Gemfile | 2 ++ Gemfile.lock | 2 ++ ...x_notifications_after_carto_migration.rake | 28 +++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 lib/tasks/deployment/20181121153709_fix_notifications_after_carto_migration.rake diff --git a/Gemfile b/Gemfile index 791180e2c..42647402b 100644 --- a/Gemfile +++ b/Gemfile @@ -127,6 +127,8 @@ gem "administrate" gem 'rack-mini-profiler' +gem 'rake-progressbar', require: false + group :test do gem 'launchy' gem 'factory_bot' diff --git a/Gemfile.lock b/Gemfile.lock index 80ace7c9b..1afdb378f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -468,6 +468,7 @@ GEM thor (>= 0.19.0, < 2.0) rainbow (3.0.0) rake (12.3.1) + rake-progressbar (0.0.5) rb-fsevent (0.10.3) rb-inotify (0.9.10) ffi (>= 0.5.0, < 2) @@ -718,6 +719,7 @@ DEPENDENCIES rails rails-controller-testing rails-i18n + rake-progressbar rbnacl-libsodium rest-client rgeo-geojson diff --git a/lib/tasks/deployment/20181121153709_fix_notifications_after_carto_migration.rake b/lib/tasks/deployment/20181121153709_fix_notifications_after_carto_migration.rake new file mode 100644 index 000000000..82a0a1954 --- /dev/null +++ b/lib/tasks/deployment/20181121153709_fix_notifications_after_carto_migration.rake @@ -0,0 +1,28 @@ +require 'rake-progressbar' + +namespace :after_party do + desc 'Deployment task: fix_notifications_after_carto_migration' + task fix_notifications_after_carto_migration: :environment do + def fix_notifications(dossier) + updated_at = dossier.champs[1..-1].map(&:updated_at).max + champ_carte = dossier.champs.first + if updated_at && (!champ_carte.updated_at || champ_carte.updated_at > updated_at) + champ_carte.update_columns(updated_at: updated_at, created_at: updated_at) + end + end + + dossiers = Dossier.includes(:champs) + .joins(procedure: :module_api_carto) + .where(procedure: { module_api_cartos: { migrated: true } }) + + bar = RakeProgressbar.new(dossiers.count) + + dossiers.find_each do |dossier| + fix_notifications(dossier) + bar.inc + end + bar.finished + + AfterParty::TaskRecord.create version: '20181121153709' + end +end