diff options
author | Louise Crow <louise.crow@gmail.com> | 2012-08-16 11:22:00 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2012-08-16 11:22:00 +0100 |
commit | 4d1ffaf2e2ad0be7a1d5b520fed816a28e52b0bb (patch) | |
tree | abf1d2df0112634b87c2097b1aae297e6e9803a0 | |
parent | ff42a5c115ddc82f60bec45c62c522b543e6b895 (diff) |
Add temp task to delete the cached attachment files for requests that have been deleted or are currently not publicly visible - having prominence requester_only or hidden.
-rw-r--r-- | lib/tasks/temp.rake | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/lib/tasks/temp.rake b/lib/tasks/temp.rake index ce04c7ddd..9decc13db 100644 --- a/lib/tasks/temp.rake +++ b/lib/tasks/temp.rake @@ -1,15 +1,44 @@ namespace :temp do - desc "Remove plaintext passwords from post_redirect params" - task :remove_post_redirect_passwords => :environment do - PostRedirect.find_each(:conditions => ['post_params_yaml is not null']) do |post_redirect| - if post_redirect.post_params && post_redirect.post_params[:signchangeemail] && post_redirect.post_params[:signchangeemail][:password] - params = post_redirect.post_params - params[:signchangeemail].delete(:password) - post_redirect.post_params = params - post_redirect.save! - end + desc "Remove plaintext passwords from post_redirect params" + task :remove_post_redirect_passwords => :environment do + PostRedirect.find_each(:conditions => ['post_params_yaml is not null']) do |post_redirect| + if post_redirect.post_params && post_redirect.post_params[:signchangeemail] && post_redirect.post_params[:signchangeemail][:password] + params = post_redirect.post_params + params[:signchangeemail].delete(:password) + post_redirect.post_params = params + post_redirect.save! + end + end + end + + desc 'Remove file caches for requests that are not publicly visible or have been destroyed' + task :remove_obsolete_info_request_caches => :environment do + dryrun = ENV['DRYRUN'] == '0' ? false : true + verbose = ENV['VERBOSE'] == '0' ? false : true + if dryrun + puts "Running in dryrun mode" + end + request_cache_path = File.join(Rails.root, 'cache', 'views', 'request', '*', '*') + Dir.glob(request_cache_path) do |request_subdir| + info_request_id = File.basename(request_subdir) + puts "Looking for InfoRequest with id #{info_request_id}" if verbose + begin + info_request = InfoRequest.find(info_request_id) + puts "Got InfoRequest #{info_request_id}" if verbose + if ! info_request.all_can_view? + puts "Deleting cache at #{request_subdir} for hidden/requester_only InfoRequest #{info_request_id}" + if ! dryrun + FileUtils.rm_rf(request_subdir) + end + end + rescue ActiveRecord::RecordNotFound + puts "Deleting cache at #{request_subdir} for deleted InfoRequest #{info_request_id}" + if ! dryrun + FileUtils.rm_rf(request_subdir) + end + end + end end - end end |