Log errors when moving attachments (#15295).
git-svn-id: http://svn.redmine.org/redmine/trunk@12249 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
10e29f2223
commit
f4aff7919a
|
@ -265,14 +265,25 @@ class Attachment < ActiveRecord::Base
|
|||
|
||||
# Moves an existing attachment to its target directory
|
||||
def move_to_target_directory!
|
||||
if !new_record? & readable?
|
||||
src = diskfile
|
||||
self.disk_directory = target_directory
|
||||
dest = diskfile
|
||||
if src != dest && FileUtils.mkdir_p(File.dirname(dest)) && FileUtils.mv(src, dest)
|
||||
update_column :disk_directory, disk_directory
|
||||
end
|
||||
return unless !new_record? & readable?
|
||||
|
||||
src = diskfile
|
||||
self.disk_directory = target_directory
|
||||
dest = diskfile
|
||||
|
||||
return if src == dest
|
||||
|
||||
if !FileUtils.mkdir_p(File.dirname(dest))
|
||||
logger.error "Could not create directory #{File.dirname(dest)}" if logger
|
||||
return
|
||||
end
|
||||
|
||||
if !FileUtils.mv(src, dest)
|
||||
logger.error "Could not move attachment from #{src} to #{dest}" if logger
|
||||
return
|
||||
end
|
||||
|
||||
update_column :disk_directory, disk_directory
|
||||
end
|
||||
|
||||
# Moves existing attachments that are stored at the root of the files
|
||||
|
|
Loading…
Reference in New Issue