From f6ccdf2244e3a31a679427a510769651c5c0d5ef Mon Sep 17 00:00:00 2001 From: technoweenie Date: Fri, 31 Aug 2012 23:25:13 -0600 Subject: [PATCH] add tasks for counting and activating users --- Rakefile | 17 +++++++++++++++++ lib/seinfeld/user.rb | 14 ++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/Rakefile b/Rakefile index ca13034..1341f8e 100644 --- a/Rakefile +++ b/Rakefile @@ -107,6 +107,23 @@ namespace :seinfeld do end end + desc "Counts active and disabled users" + task :count => :init do + active = Seinfeld::User.active.count + disabled = Seinfeld::User.count - active + puts "#{active} active users, #{disabled} disabled users" + end + + desc "Re-enables a USER." + task :activate => :init do + login = ENV['user'].to_s + if login.size.zero? + Seinfeld::User.activate_group(50) + else + Seinfeld::User.activate_user(login) + end + end + desc "Update the calendar of USER" task :update => :init do ENV['FEED_PAGE'] ||= '1' diff --git a/lib/seinfeld/user.rb b/lib/seinfeld/user.rb index 1b53d4e..b2d1ead 100644 --- a/lib/seinfeld/user.rb +++ b/lib/seinfeld/user.rb @@ -31,6 +31,20 @@ def login=(s) write_attribute :login, s.blank? ? nil : s.downcase end + def self.activate_group(limit = 50) + disabled = connection.quote_column_name :disabled + truthy = connection.quoted_true + falsey = connection.quoted_false + sql = "UPDATE #{quoted_table_name} SET #{disabled} = #{falsey} WHERE #{disabled} = #{truthy} LIMIT #{limit.to_i}" + connection.execute(sql) + end + + def self.activate_user(login) + if user = find_by_login(login) + user.update_attributes :disabled => false + end + end + # Public: Queries a user's progress for a given month. # # Example