Skip to content

Commit

Permalink
add tasks for counting and activating users
Browse files Browse the repository at this point in the history
  • Loading branch information
technoweenie committed Sep 1, 2012
1 parent fccf0e7 commit f6ccdf2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Rakefile
Expand Up @@ -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'
Expand Down
14 changes: 14 additions & 0 deletions lib/seinfeld/user.rb
Expand Up @@ -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
Expand Down

0 comments on commit f6ccdf2

Please sign in to comment.