From 1233e108e49b74f8e844280ff313956663e5c499 Mon Sep 17 00:00:00 2001 From: Yuki Date: Tue, 28 Apr 2015 14:16:02 +0530 Subject: [PATCH] Further fix retrospring/bugs#41 --- Rakefile | 33 +++++++++++++++++++++++++++++++-- app/models/question.rb | 6 ++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index fba3b892..174dded1 100644 --- a/Rakefile +++ b/Rakefile @@ -237,6 +237,24 @@ namespace :justask do puts "Put #{destroyed} subscriptions up for adoption." end + desc "Fixes reports" + task fix_reports: :enviornment do + format = '%t (%c/%C) [%b>%i] %e' + + total = Report.count + progress = ProgressBar.create title: 'Processing reports', format: format, starting_at: 0, total: total + destroyed = 0 + Report.all.each do |r| + if r.target.nil? + r.deleted = true + r.save + destroyed += 1 + progress.increment + end + + puts "Marked #{destroyed} reports as deleted." + end + desc "Fixes everything else" task fix_db: :environment do format = '%t (%c/%C) [%b>%i] %e' @@ -246,7 +264,8 @@ namespace :justask do answer: 0, smile: 0, comment: 0, - subscription: 0 + subscription: 0, + report: 0 } total = Inbox.count @@ -301,13 +320,23 @@ namespace :justask do progress.increment end - puts "Put #{destroyed} subscriptions up for adoption." + total = Report.count + progress = ProgressBar.create title: 'Processing reports', format: format, starting_at: 0, total: total + Report.all.each do |r| + if r.target.nil? + r.deleted = true + r.save + destroyed_count[:report] += 1 + progress.increment + end + puts "Put #{destroyed_count[:subscription]} subscriptions up for adoption." puts "Purged #{destroyed_count[:inbox]} dead inbox entries." puts "Marked #{destroyed_count[:question]} questions as anonymous." puts "Purged #{destroyed_count[:answer]} dead answers." puts "Purged #{destroyed_count[:answer]} dead comments." puts "Purged #{destroyed_count[:subscription]} dead subscriptions." + puts "Marked #{destroyed_count[:report]} reports as deleted." end desc "Prints lonely people." diff --git a/app/models/question.rb b/app/models/question.rb index 5f8289e4..27e33b61 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -6,6 +6,12 @@ class Question < ActiveRecord::Base validates :content, length: { maximum: 255 } before_destroy do + rep = Report.where(target_id: self.id).first + unless rep.nil? + rep.deleted = true + rep.save + end + user.decrement! :asked_count unless self.author_is_anonymous end