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 4359340
Showing 1 changed file with 18 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!
print "."
rescue Mongoid::Errors::Validations
puts "Failed to delete asset of ID #{asset_id}: #{asset.errors.full_messages}"
end
end
end
end

0 comments on commit 4359340

Please sign in to comment.