Further fix retrospring/bugs#41
This commit is contained in:
parent
d012423b29
commit
1233e108e4
33
Rakefile
33
Rakefile
|
@ -237,6 +237,24 @@ namespace :justask do
|
||||||
puts "Put #{destroyed} subscriptions up for adoption."
|
puts "Put #{destroyed} subscriptions up for adoption."
|
||||||
end
|
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"
|
desc "Fixes everything else"
|
||||||
task fix_db: :environment do
|
task fix_db: :environment do
|
||||||
format = '%t (%c/%C) [%b>%i] %e'
|
format = '%t (%c/%C) [%b>%i] %e'
|
||||||
|
@ -246,7 +264,8 @@ namespace :justask do
|
||||||
answer: 0,
|
answer: 0,
|
||||||
smile: 0,
|
smile: 0,
|
||||||
comment: 0,
|
comment: 0,
|
||||||
subscription: 0
|
subscription: 0,
|
||||||
|
report: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
total = Inbox.count
|
total = Inbox.count
|
||||||
|
@ -301,13 +320,23 @@ namespace :justask do
|
||||||
progress.increment
|
progress.increment
|
||||||
end
|
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 "Purged #{destroyed_count[:inbox]} dead inbox entries."
|
||||||
puts "Marked #{destroyed_count[:question]} questions as anonymous."
|
puts "Marked #{destroyed_count[:question]} questions as anonymous."
|
||||||
puts "Purged #{destroyed_count[:answer]} dead answers."
|
puts "Purged #{destroyed_count[:answer]} dead answers."
|
||||||
puts "Purged #{destroyed_count[:answer]} dead comments."
|
puts "Purged #{destroyed_count[:answer]} dead comments."
|
||||||
puts "Purged #{destroyed_count[:subscription]} dead subscriptions."
|
puts "Purged #{destroyed_count[:subscription]} dead subscriptions."
|
||||||
|
puts "Marked #{destroyed_count[:report]} reports as deleted."
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Prints lonely people."
|
desc "Prints lonely people."
|
||||||
|
|
|
@ -6,6 +6,12 @@ class Question < ActiveRecord::Base
|
||||||
validates :content, length: { maximum: 255 }
|
validates :content, length: { maximum: 255 }
|
||||||
|
|
||||||
before_destroy do
|
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
|
user.decrement! :asked_count unless self.author_is_anonymous
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue