Browse Source

Enforce dry run only

pull/2494/head
Rachael Booth 2 years ago
parent
commit
a4ca6f937b
  1. 22
      lib/tasks/handle_unpended_logs.rake

22
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" 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| task :handle_unpended_logs, %i[perform_updates] => :environment do |_task, _args|
dry_run = args[:perform_updates].blank? || args[:perform_updates] != "true" dry_run = true # args[:perform_updates].blank? || args[:perform_updates] != "true"
pg = ActiveRecord::Base.connection 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%'))" 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| affected_non_updated_duplicates.each do |d|
seen.add(d.id) 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] 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 # unless dry_run
d.discard! # d.discard!
end # end
end end
next next
end end
@ -133,9 +133,9 @@ task :handle_unpended_logs, %i[perform_updates] => :environment do |_task, args|
affected_non_updated_duplicates.each do |d| affected_non_updated_duplicates.each do |d|
seen.add(d.id) 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] 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 # unless dry_run
d.discard! # d.discard!
end # end
end end
next next
end end
@ -149,9 +149,9 @@ task :handle_unpended_logs, %i[perform_updates] => :environment do |_task, args|
seen.add(d.id) 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] 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 # unless dry_run
d.discard! # d.discard!
end # end
end end
end end
end end

Loading…
Cancel
Save