Patch by Yuichi HARADA and Marius BALTEANU.
git-svn-id: https://svn.redmine.org/redmine/trunk@21490
e93f8b46-1217-0410-a6f0-
8f06a7374b81
project_ids.map(&:to_i)
end
+ def self.prune(age)
+ User.where("created_on < ? AND status = ?", Time.now - age, STATUS_REGISTERED).destroy_all
+ end
+
protected
def validate_password_length
end
end
+ namespace :users do
+ desc 'Removes registered users that have not been activated after a number of days. Use DAYS to set the number of days, defaults to 30 days.'
+ task :prune => :environment do
+ days = 30
+ env_days = ENV['DAYS']
+ if env_days
+ if env_days.to_i <= 0
+ abort "Invalid DAYS #{env_days} given. The value must be a integer."
+ else
+ days = env_days.to_i
+ end
+ end
+ User.prune(days.days)
+ end
+ end
+
namespace :watchers do
desc 'Removes watchers from what they can no longer view.'
task :prune => :environment do
cv2a.reload
assert_equal @dlopper.id.to_s, cv2a.value
end
+
+ def test_prune_should_destroy_unactivated_old_users
+ User.generate!(:status => User::STATUS_REGISTERED, :created_on => 6.days.ago)
+ User.generate!(:status => User::STATUS_REGISTERED, :created_on => 7.days.ago)
+ User.generate!(:status => User::STATUS_REGISTERED)
+
+ assert_difference 'User.count', -2 do
+ User.prune(7)
+ end
+ end
end