Skip to content

Commit

Permalink
Add temproary soft delete bulk rake task
Browse files Browse the repository at this point in the history
This is part of running a clean-up on assets that should be deleted, according to whitehall.
We discovered a set of assets that have an invalid deleted state, so we're resetting them to "uploaded".
  • Loading branch information
lauraghiorghisor-tw committed Nov 20, 2024
1 parent c63302f commit 0bdf3c5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/tasks/assets.rake
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,22 @@ namespace :assets do
asset = WhitehallAsset.find_by!(legacy_url_path:)
puts "Asset ID for #{legacy_url_path} is #{asset.id}."
end

desc "Soft delete assets and check deleted invalid state"
task :bulk_soft_delete, %i[csv_path] => :environment do |_t, args|
csv_path = args.fetch(:csv_path)

CSV.foreach(csv_path, headers: false) do |row|
asset_id = row[0]
asset = Asset.find(asset_id)
asset.state = "uploaded" if asset.state == "deleted"

begin
asset.destroy!
puts "Delete asset of ID #{asset_id}: OK"
rescue Mongoid::Errors::Validations
puts "Failed to delete asset of ID #{asset_id}: #{asset.errors.full_messages}"
end
end
end
end
7 changes: 7 additions & 0 deletions lib/tasks/assets_to_delete.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
5a7de75ded915d74e6222d1d
5a7e4067ed915d74e622518b
5a7e4067e5274a2e87db0856
5a7d8000ed915d269ba8b0bd
5a7d7fffe5274a676d5326f3
5a7e4461e5274a2e87db09f5
5de6fcdc40f0b650bf4dee49

0 comments on commit 0bdf3c5

Please sign in to comment.