Skip to content

Commit

Permalink
Merge pull request #1543 from alphagov/add-temporary-rake-task-for-as…
Browse files Browse the repository at this point in the history
…set-deletion

Add temproary soft delete bulk rake task
  • Loading branch information
lauraghiorghisor-tw authored Nov 20, 2024
2 parents c63302f + 4359340 commit 709a544
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 709a544

Please sign in to comment.