From 13101fd7188c7118ead4c14a28cd8bc5d1855a08 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Mon, 10 Jun 2013 11:35:52 -0700 Subject: Remove old temp tasks. --- lib/tasks/temp.rake | 50 -------------------------------------------------- 1 file changed, 50 deletions(-) (limited to 'lib/tasks/temp.rake') diff --git a/lib/tasks/temp.rake b/lib/tasks/temp.rake index f0085b5e1..bc25b78f9 100644 --- a/lib/tasks/temp.rake +++ b/lib/tasks/temp.rake @@ -1,55 +1,5 @@ namespace :temp do - desc 'Populate the request_classifications table from info_request_events' - task :populate_request_classifications => :environment do - InfoRequestEvent.find_each(:conditions => ["event_type = 'status_update'"]) do |classification| - RequestClassification.create!(:created_at => classification.created_at, - :user_id => classification.params[:user_id], - :info_request_event_id => classification.id) - end - 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 - desc 'Create a CSV file of a random selection of raw emails, for comparing hexdigests' task :random_attachments_hexdigests => :environment do -- cgit v1.2.3 From 629e85265f20b532072ef238ccf7a0660b7747b6 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Mon, 10 Jun 2013 11:41:28 -0700 Subject: Add a task for cleaning up user accounts that were created with a space in the email address. --- lib/tasks/temp.rake | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'lib/tasks/temp.rake') diff --git a/lib/tasks/temp.rake b/lib/tasks/temp.rake index bc25b78f9..4f26953de 100644 --- a/lib/tasks/temp.rake +++ b/lib/tasks/temp.rake @@ -1,5 +1,70 @@ namespace :temp do + def disable_duplicate_account(user, count, dryrun) + dupe_email = "duplicateemail#{count}@example.com" + puts "Updating #{user.email} to #{dupe_email} for user #{user.id}" + user.email = dupe_email + user.save! unless dryrun + end + + desc 'Cleanup accounts with a space in the email address' + task :clean_up_emails_with_spaces => :environment do + dryrun = ENV['DRYRUN'] == '0' ? false : true + if dryrun + puts "This is a dryrun" + end + User.find_each do |user| + if / /.match(user.email) + count = 0 + email_without_spaces = user.email.gsub(' ', '') + existing = User.find_by_email(email_without_spaces) + # Another account exists with the canonical address + if existing + if user.info_requests.count == 0 and user.comments.count == 0 and user.track_things.count == 0 + count += 1 + disable_duplicate_account(user) + elsif existing.info_requests.count == 0 and existing.comments.count == 0 and existing.track_things.count == 0 + count += 1 + disable_duplicate_account(existing) + user.email = email_without_spaces + user.save! unless dryrun + else + user.info_requests.each do |info_request| + info_request.user = existing + info_request.save! unless dryrun + end + user.comments.each do |comment| + comment.user = existing + comment.save! unless dryrun + end + user.track_things.each do |track_thing| + track_thing.user = existing + track_thing.save! unless dryrun + end + user.track_thing_sent_email.each do |sent_email| + sent_email.user = existing + sent_email.save! unless dryrun + end + user.censor_rules.each do |censor_rule| + censor_rule.user = existing + censor_rule.save! unless dryrun + end + user.info_request_sent_alert.each do |sent_alert| + sent_alert.user = existing + sent_alert.save! unless dryrun + end + count += 1 + disable_duplicate_account(user) + end + else + puts "Updating #{user.email} to #{email_without_spaces} for user #{user.id}" + user.email = email_without_spaces + user.save! unless dryrun + end + end + end + end + desc 'Create a CSV file of a random selection of raw emails, for comparing hexdigests' task :random_attachments_hexdigests => :environment do -- cgit v1.2.3 From 9dbeff4231e20dc79fb790af13e3f7f450fe6349 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Mon, 10 Jun 2013 12:44:23 -0700 Subject: Fix syntax errors, add some debug output. --- lib/tasks/temp.rake | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'lib/tasks/temp.rake') diff --git a/lib/tasks/temp.rake b/lib/tasks/temp.rake index 4f26953de..a1d508142 100644 --- a/lib/tasks/temp.rake +++ b/lib/tasks/temp.rake @@ -13,48 +13,62 @@ namespace :temp do if dryrun puts "This is a dryrun" end + count = 0 User.find_each do |user| if / /.match(user.email) - count = 0 + email_without_spaces = user.email.gsub(' ', '') - existing = User.find_by_email(email_without_spaces) + existing = User.find_user_by_email(email_without_spaces) # Another account exists with the canonical address if existing if user.info_requests.count == 0 and user.comments.count == 0 and user.track_things.count == 0 count += 1 - disable_duplicate_account(user) + disable_duplicate_account(user, count, dryrun) elsif existing.info_requests.count == 0 and existing.comments.count == 0 and existing.track_things.count == 0 count += 1 - disable_duplicate_account(existing) + disable_duplicate_account(existing, count, dryrun) user.email = email_without_spaces user.save! unless dryrun else user.info_requests.each do |info_request| info_request.user = existing info_request.save! unless dryrun + puts "Moved request #{info_request.id} from user #{user.id} to #{existing.id}" end + user.comments.each do |comment| comment.user = existing comment.save! unless dryrun + puts "Moved comment #{comment.id} from user #{user.id} to #{existing.id}" end + user.track_things.each do |track_thing| - track_thing.user = existing + track_thing.tracking_user = existing track_thing.save! unless dryrun + puts "Moved track thing #{track_thing.id} from user #{user.id} to #{existing.id}" end - user.track_thing_sent_email.each do |sent_email| + + TrackThingsSentEmail.find_each(:conditions => ['user_id = ?', user]) do |sent_email| sent_email.user = existing sent_email.save! unless dryrun + puts "Moved track thing sent email #{sent_email.id} from user #{user.id} to #{existing.id}" + end + user.censor_rules.each do |censor_rule| censor_rule.user = existing censor_rule.save! unless dryrun + puts "Moved censor rule #{censor_rule.id} from user #{user.id} to #{existing.id}" end - user.info_request_sent_alert.each do |sent_alert| + + user.user_info_request_sent_alerts.each do |sent_alert| sent_alert.user = existing sent_alert.save! unless dryrun + puts "Moved sent alert #{sent_alert.id} from user #{user.id} to #{existing.id}" end + count += 1 - disable_duplicate_account(user) + disable_duplicate_account(user, count, dryrun) end else puts "Updating #{user.email} to #{email_without_spaces} for user #{user.id}" -- cgit v1.2.3 From ad2845ecd00840b21092fda676aabb15f6ea51ae Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Mon, 10 Jun 2013 13:29:35 -0700 Subject: Add extra debug line --- lib/tasks/temp.rake | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/tasks/temp.rake') diff --git a/lib/tasks/temp.rake b/lib/tasks/temp.rake index a1d508142..35ae442c7 100644 --- a/lib/tasks/temp.rake +++ b/lib/tasks/temp.rake @@ -28,6 +28,7 @@ namespace :temp do count += 1 disable_duplicate_account(existing, count, dryrun) user.email = email_without_spaces + puts "Updating #{user.email} to #{email_without_spaces} for user #{user.id}" user.save! unless dryrun else user.info_requests.each do |info_request| -- cgit v1.2.3