From ababb3894ca1931d5ade6b93f7a5d1c20e699d54 Mon Sep 17 00:00:00 2001 From: Rachael Booth Date: Wed, 10 Jul 2024 10:25:50 +0100 Subject: [PATCH] CLDC-3543: Allow live run of handle unpended logs task (#2496) --- lib/tasks/handle_unpended_logs.rake | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/tasks/handle_unpended_logs.rake b/lib/tasks/handle_unpended_logs.rake index fda99687e..02c976682 100644 --- a/lib/tasks/handle_unpended_logs.rake +++ b/lib/tasks/handle_unpended_logs.rake @@ -1,6 +1,6 @@ desc "Deduplicates logs where we have inadvertently turned some pending logs to in progress / completed" task :handle_unpended_logs, %i[perform_updates] => :environment do |_task, _args| - dry_run = true # args[:perform_updates].blank? || args[:perform_updates] != "true" + dry_run = args[:perform_updates].blank? || args[:perform_updates] != "true" pg = ActiveRecord::Base.connection query = "SELECT \"versions\".* FROM \"versions\" WHERE \"versions\".\"item_type\" = 'LettingsLog' AND whodunnit is null AND ((object_changes like '%status:\n- 3\n- 1%') OR (object_changes like '%status:\n- 3\n- 2%'))" @@ -115,9 +115,9 @@ task :handle_unpended_logs, %i[perform_updates] => :environment do |_task, _args affected_non_updated_duplicates.each do |d| seen.add(d.id) csv << [d.id, d.collection_start_year, d.status, d.owning_organisation_name, d.assigned_to_id, d.assigned_to.email, "Delete", "Log is a duplicate of unaffected log(s)", unaffected_logs_reference] - # unless dry_run - # d.discard! - # end + unless dry_run + d.discard! + end end next end @@ -133,9 +133,9 @@ task :handle_unpended_logs, %i[perform_updates] => :environment do |_task, _args affected_non_updated_duplicates.each do |d| seen.add(d.id) csv << [d.id, d.collection_start_year, d.status, d.owning_organisation_name, d.assigned_to_id, d.assigned_to.email, "Delete", "Log is a duplicate of log(s) which have been updated since being affected", updated_logs_reference] - # unless dry_run - # d.discard! - # end + unless dry_run + d.discard! + end end next end @@ -149,9 +149,9 @@ task :handle_unpended_logs, %i[perform_updates] => :environment do |_task, _args seen.add(d.id) csv << [d.id, d.collection_start_year, d.status, d.owning_organisation_name, d.assigned_to_id, d.assigned_to.email, "Delete", "Log is a duplicate of more recently created affected log", latest_created.id] - # unless dry_run - # d.discard! - # end + unless dry_run + d.discard! + end end end end