comparison app/models/watcher.rb @ 1295:622f24f53b42 redmine-2.3

Update to Redmine SVN revision 11972 on 2.3-stable branch
author Chris Cannam
date Fri, 14 Jun 2013 09:02:21 +0100
parents 433d4f72a19b
children
comparison
equal deleted inserted replaced
1294:3e4c3460b6ca 1295:622f24f53b42
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
27 def self.prune(options={}) 27 def self.prune(options={})
28 if options.has_key?(:user) 28 if options.has_key?(:user)
29 prune_single_user(options[:user], options) 29 prune_single_user(options[:user], options)
30 else 30 else
31 pruned = 0 31 pruned = 0
32 User.find(:all, :conditions => "id IN (SELECT DISTINCT user_id FROM #{table_name})").each do |user| 32 User.where("id IN (SELECT DISTINCT user_id FROM #{table_name})").all.each do |user|
33 pruned += prune_single_user(user, options) 33 pruned += prune_single_user(user, options)
34 end 34 end
35 pruned 35 pruned
36 end 36 end
37 end 37 end
45 private 45 private
46 46
47 def self.prune_single_user(user, options={}) 47 def self.prune_single_user(user, options={})
48 return unless user.is_a?(User) 48 return unless user.is_a?(User)
49 pruned = 0 49 pruned = 0
50 find(:all, :conditions => {:user_id => user.id}).each do |watcher| 50 where(:user_id => user.id).all.each do |watcher|
51 next if watcher.watchable.nil? 51 next if watcher.watchable.nil?
52 52
53 if options.has_key?(:project) 53 if options.has_key?(:project)
54 next unless watcher.watchable.respond_to?(:project) && watcher.watchable.project == options[:project] 54 next unless watcher.watchable.respond_to?(:project) && watcher.watchable.project == options[:project]
55 end 55 end