@@ -0,0 +1,26 | |||
|
1 | # Redmine - project management software | |
|
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang | |
|
3 | # | |
|
4 | # This program is free software; you can redistribute it and/or | |
|
5 | # modify it under the terms of the GNU General Public License | |
|
6 | # as published by the Free Software Foundation; either version 2 | |
|
7 | # of the License, or (at your option) any later version. | |
|
8 | # | |
|
9 | # This program is distributed in the hope that it will be useful, | |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
12 | # GNU General Public License for more details. | |
|
13 | # | |
|
14 | # You should have received a copy of the GNU General Public License | |
|
15 | # along with this program; if not, write to the Free Software | |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
|
17 | ||
|
18 | desc 'Removes uploaded files left unattached after one day.' | |
|
19 | ||
|
20 | namespace :redmine do | |
|
21 | namespace :attachments do | |
|
22 | task :prune => :environment do | |
|
23 | Attachment.prune | |
|
24 | end | |
|
25 | end | |
|
26 | end |
@@ -192,7 +192,7 class Attachment < ActiveRecord::Base | |||
|
192 | 192 | end |
|
193 | 193 | |
|
194 | 194 | def self.prune(age=1.day) |
|
195 | attachments = Attachment.all(:conditions => ["created_on < ? AND (container_type IS NULL OR container_type = ''", Time.now - age]) | |
|
195 | attachments = Attachment.all(:conditions => ["created_on < ? AND (container_type IS NULL OR container_type = '')", Time.now - age]) | |
|
196 | 196 | attachments.each(&:destroy) |
|
197 | 197 | end |
|
198 | 198 |
@@ -144,6 +144,16 class AttachmentTest < ActiveSupport::TestCase | |||
|
144 | 144 | assert_equal 'cbb5b0f30978ba03731d61f9f6d10011', Attachment.disk_filename("test_accentué.ça")[13..-1] |
|
145 | 145 | end |
|
146 | 146 | |
|
147 | def test_prune_should_destroy_old_unattached_attachments | |
|
148 | Attachment.create!(:file => uploaded_test_file("testfile.txt", ""), :author_id => 1, :created_on => 2.days.ago) | |
|
149 | Attachment.create!(:file => uploaded_test_file("testfile.txt", ""), :author_id => 1, :created_on => 2.days.ago) | |
|
150 | Attachment.create!(:file => uploaded_test_file("testfile.txt", ""), :author_id => 1) | |
|
151 | ||
|
152 | assert_difference 'Attachment.count', -2 do | |
|
153 | Attachment.prune | |
|
154 | end | |
|
155 | end | |
|
156 | ||
|
147 | 157 | context "Attachmnet.attach_files" do |
|
148 | 158 | should "attach the file" do |
|
149 | 159 | issue = Issue.first |
General Comments 0
You need to be logged in to leave comments.
Login now