Browse Source

CLDC-3543: Allow live run of handle unpended logs task (#2496)

pull/2503/head v0.4.55
Rachael Booth 6 months ago committed by GitHub
parent
commit
ababb3894c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 20
      lib/tasks/handle_unpended_logs.rake

20
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 = true # args[:perform_updates].blank? || args[:perform_updates] != "true" dry_run = 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