2014-08-01 02:23:47 -07:00
|
|
|
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
|
|
|
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
|
|
|
|
|
|
|
require File.expand_path('../config/application', __FILE__)
|
|
|
|
|
|
|
|
Rails.application.load_tasks
|
2014-11-28 13:02:32 -08:00
|
|
|
|
|
|
|
namespace :justask do
|
2014-11-30 10:47:39 -08:00
|
|
|
desc "Recount everything!"
|
2014-11-28 13:02:32 -08:00
|
|
|
task recount: :environment do
|
2014-11-30 10:47:39 -08:00
|
|
|
format = '%t (%c/%C) [%b>%i] %e'
|
2014-11-28 13:02:32 -08:00
|
|
|
total = User.count
|
2014-11-30 10:47:39 -08:00
|
|
|
progress = ProgressBar.create title: 'Processing users', format: format, starting_at: 0, total: total
|
2014-11-28 13:11:36 -08:00
|
|
|
User.all.each do |user|
|
2014-11-28 13:02:32 -08:00
|
|
|
begin
|
2014-11-29 03:21:42 -08:00
|
|
|
answered = Answer.where(user: user).count
|
2014-11-28 13:02:32 -08:00
|
|
|
asked = Question.where(user: user).where(author_is_anonymous: false).count
|
2014-11-29 03:21:42 -08:00
|
|
|
commented = Comment.where(user: user).count
|
2014-11-30 10:47:39 -08:00
|
|
|
smiled = Smile.where(user: user).count
|
2014-11-30 05:56:06 -08:00
|
|
|
user.friend_count = user.friends.count
|
|
|
|
user.follower_count = user.followers.count
|
2014-11-28 13:02:32 -08:00
|
|
|
user.answered_count = answered
|
|
|
|
user.asked_count = asked
|
|
|
|
user.commented_count = commented
|
2014-11-30 10:47:39 -08:00
|
|
|
user.smiled_count = smiled
|
2014-11-28 13:02:32 -08:00
|
|
|
user.save!
|
|
|
|
end
|
|
|
|
progress.increment
|
|
|
|
end
|
2014-11-30 10:47:39 -08:00
|
|
|
total = Answer.count
|
|
|
|
progress = ProgressBar.create title: 'Processing answers', format: format, starting_at: 0, total: total
|
|
|
|
Answer.all.each do |answer|
|
|
|
|
begin
|
|
|
|
smiles = Smile.where(answer: answer).count
|
|
|
|
answer.smile_count = smiles
|
|
|
|
answer.save!
|
|
|
|
end
|
|
|
|
progress.increment
|
|
|
|
end
|
2014-11-28 13:02:32 -08:00
|
|
|
end
|
2014-11-28 13:31:29 -08:00
|
|
|
|
|
|
|
desc "Gives admin status to an user."
|
|
|
|
task :admin, [:screen_name] => :environment do |t, args|
|
|
|
|
fail "screen name required" if args[:screen_name].nil?
|
|
|
|
user = User.find_by_screen_name(args[:screen_name])
|
|
|
|
fail "user #{args[:screen_name]} not found" if user.nil?
|
|
|
|
user.admin = true
|
|
|
|
user.save!
|
|
|
|
puts "#{user.screen_name} is now an admin"
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "Removes admin status from an user."
|
|
|
|
task :deadmin, [:screen_name] => :environment do |t, args|
|
|
|
|
fail "screen name required" if args[:screen_name].nil?
|
|
|
|
user = User.find_by_screen_name(args[:screen_name])
|
|
|
|
fail "user #{args[:screen_name]} not found" if user.nil?
|
|
|
|
user.admin = false
|
|
|
|
user.save!
|
|
|
|
puts "#{user.screen_name} no longer an admin"
|
|
|
|
end
|
2014-11-29 15:16:42 -08:00
|
|
|
|
|
|
|
desc "Lists all users."
|
|
|
|
task lusers: :environment do
|
|
|
|
User.all.each do |u|
|
|
|
|
puts "#{sprintf "%3d", u.id}. #{u.screen_name}"
|
|
|
|
end
|
|
|
|
end
|
2014-11-29 03:21:42 -08:00
|
|
|
end
|