mirror of
https://github.com/meineerde/redmine.git
synced 2026-02-23 12:01:46 +00:00
Deletes thumbnails when the attachment diskfile is deleted (#30177).
Patch by Jens Krämer. git-svn-id: http://svn.redmine.org/redmine/trunk@17736 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
bda0de0044
commit
cccd14ae5c
@ -216,7 +216,7 @@ class Attachment < ActiveRecord::Base
|
|||||||
size = Setting.thumbnails_size.to_i
|
size = Setting.thumbnails_size.to_i
|
||||||
end
|
end
|
||||||
size = 100 unless size > 0
|
size = 100 unless size > 0
|
||||||
target = File.join(self.class.thumbnails_storage_path, "#{digest}_#{filesize}_#{size}.thumb")
|
target = thumbnail_path(size)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Redmine::Thumbnail.generate(self.diskfile, target, size)
|
Redmine::Thumbnail.generate(self.diskfile, target, size)
|
||||||
@ -463,6 +463,14 @@ class Attachment < ActiveRecord::Base
|
|||||||
if disk_filename.present? && File.exist?(diskfile)
|
if disk_filename.present? && File.exist?(diskfile)
|
||||||
File.delete(diskfile)
|
File.delete(diskfile)
|
||||||
end
|
end
|
||||||
|
Dir[thumbnail_path("*")].each do |thumb|
|
||||||
|
File.delete(thumb)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def thumbnail_path(size)
|
||||||
|
File.join(self.class.thumbnails_storage_path,
|
||||||
|
"#{digest}_#{filesize}_#{size}.thumb")
|
||||||
end
|
end
|
||||||
|
|
||||||
def sanitize_filename(value)
|
def sanitize_filename(value)
|
||||||
|
|||||||
@ -457,6 +457,21 @@ class AttachmentTest < ActiveSupport::TestCase
|
|||||||
assert_equal a_thumb, b_thumb
|
assert_equal a_thumb, b_thumb
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_destroy_should_destroy_thumbnails
|
||||||
|
a = Attachment.create!(
|
||||||
|
:container => Issue.find(1),
|
||||||
|
:file => uploaded_test_file("2010/11/101123161450_testfile_1.png", "image/png"),
|
||||||
|
:author => User.find(1)
|
||||||
|
)
|
||||||
|
diskfile = a.diskfile
|
||||||
|
thumbnail = a.thumbnail
|
||||||
|
assert File.exist?(diskfile)
|
||||||
|
assert File.exist?(thumbnail)
|
||||||
|
assert a.destroy
|
||||||
|
refute File.exist?(diskfile)
|
||||||
|
refute File.exist?(thumbnail)
|
||||||
|
end
|
||||||
|
|
||||||
def test_thumbnail_should_return_nil_if_generation_fails
|
def test_thumbnail_should_return_nil_if_generation_fails
|
||||||
Redmine::Thumbnail.expects(:generate).raises(SystemCallError, 'Something went wrong')
|
Redmine::Thumbnail.expects(:generate).raises(SystemCallError, 'Something went wrong')
|
||||||
set_fixtures_attachments_directory
|
set_fixtures_attachments_directory
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user