Code cleanup.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9716 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-05-25 20:51:43 +00:00
parent aa18cd54c7
commit d664fdcde9

View File

@ -175,7 +175,7 @@ class Attachment < ActiveRecord::Base
def self.find_by_token(token) def self.find_by_token(token)
if token.to_s =~ /^(\d+)\.([0-9a-f]+)$/ if token.to_s =~ /^(\d+)\.([0-9a-f]+)$/
attachment_id, attachment_digest = $1, $2 attachment_id, attachment_digest = $1, $2
attachment = Attachment.first(:conditions => {:id => attachment_id, :digest => attachment_digest}) attachment = Attachment.where(:id => attachment_id, :digest => attachment_digest).first
if attachment && attachment.container.nil? if attachment && attachment.container.nil?
attachment attachment
end end
@ -200,8 +200,7 @@ class Attachment < ActiveRecord::Base
end end
def self.prune(age=1.day) def self.prune(age=1.day)
attachments = Attachment.all(:conditions => ["created_on < ? AND (container_type IS NULL OR container_type = '')", Time.now - age]) Attachment.where("created_on < ? AND (container_type IS NULL OR container_type = '')", Time.now - age).destroy_all
attachments.each(&:destroy)
end end
private private