Make the storage path Rails.root related #733
This commit is contained in:
parent
446c38d83d
commit
21fb2aa865
@ -4,6 +4,11 @@ Changelog for Redmine DMSF
|
||||
1.6.0 *????-??-??*
|
||||
------------------
|
||||
|
||||
IMPORTANT
|
||||
|
||||
1. Files in the filesystem are re-organized by a new system based on date.
|
||||
2. DMS storage directory plugin option is related to the rails root directory.
|
||||
|
||||
1.5.9 *2016-03-01*
|
||||
------------------
|
||||
|
||||
|
||||
@ -102,10 +102,12 @@ class DmsfFile < ActiveRecord::Base
|
||||
def self.storage_path
|
||||
return @@storage_path if @@storage_path.present?
|
||||
path = Setting.plugin_redmine_dmsf['dmsf_storage_directory']
|
||||
path = Pathname(Redmine::Configuration['attachments_storage_path']).join('dmsf') if path.blank? && Redmine::Configuration['attachments_storage_path'].present?
|
||||
path = Rails.root.join('files/dmsf').to_s if path.blank?
|
||||
path.strip if path
|
||||
path
|
||||
if path.blank?
|
||||
path = 'dmsf'
|
||||
else
|
||||
path.strip!
|
||||
end
|
||||
Rails.root.join(path)
|
||||
end
|
||||
|
||||
# Lets introduce a write for storage path, that way we can also
|
||||
|
||||
@ -133,20 +133,20 @@ class DmsfFileRevision < ActiveRecord::Base
|
||||
def storage_base_path
|
||||
time = self.created_at || DateTime.now
|
||||
path = time.strftime('%Y/%m')
|
||||
"#{DmsfFile.storage_path}/#{path}"
|
||||
DmsfFile.storage_path.join path
|
||||
end
|
||||
|
||||
def disk_file
|
||||
path = self.storage_base_path
|
||||
FileUtils.mkdir_p(path) unless File.exist?(path)
|
||||
"#{path}/#{self.disk_filename}"
|
||||
path.join self.disk_filename
|
||||
end
|
||||
|
||||
def new_storage_filename
|
||||
raise DmsfAccessError, 'File id is not set' unless self.dmsf_file.id
|
||||
filename = DmsfHelper.sanitize_filename(self.name)
|
||||
timestamp = DateTime.now.strftime("%y%m%d%H%M%S")
|
||||
while File.exist?(File.join(storage_base_path, "#{timestamp}_#{self.dmsf_file.id}_#{filename}"))
|
||||
while File.exist?(storage_base_path.join("#{timestamp}_#{self.dmsf_file.id}_#{filename}"))
|
||||
timestamp.succ!
|
||||
end
|
||||
"#{timestamp}_#{self.dmsf_file.id}_#{filename}"
|
||||
|
||||
@ -62,21 +62,21 @@
|
||||
<%= content_tag(:label, l(:label_file_storage_directory)) %>
|
||||
<%
|
||||
storage_dir = @settings['dmsf_storage_directory'].strip if @settings['dmsf_storage_directory'].present?
|
||||
storage_dir = "#{Rails.root}/files/dmsf" if storage_dir.blank?
|
||||
storage_dir = 'dmsf' if storage_dir.blank?
|
||||
%>
|
||||
<%= text_field_tag 'settings[dmsf_storage_directory]', storage_dir, :size => 50 %>
|
||||
<em class="info">
|
||||
<%= l(:label_default) %>: <%= "#{Rails.root}/files/dmsf" %>
|
||||
<%= l(:label_default) %>: dmsf
|
||||
</em>
|
||||
</p>
|
||||
<% unless File.exist?(storage_dir) %>
|
||||
<% unless File.exist?(DmsfFile.storage_path) %>
|
||||
<% begin %>
|
||||
<% Dir.mkdir(storage_dir) %>
|
||||
<% Dir.mkdir(DmsfFile.storage_path) %>
|
||||
<% rescue %>
|
||||
<p class="warning"><%= l(:error_file_storage_directory_does_not_exist) %></p>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% testfilename = "#{storage_dir}/test.test" %>
|
||||
<% testfilename = DmsfFile.storage_path.join('test.test') %>
|
||||
<% if File.exist?(storage_dir) %>
|
||||
<% begin %>
|
||||
<% File.open(testfilename, 'wb') do |file| %>
|
||||
|
||||
@ -88,7 +88,7 @@ class Dmsf144 < ActiveRecord::Migration
|
||||
begin
|
||||
DmsfFileRevision.visible.each {|rev|
|
||||
next if rev.project.nil?
|
||||
existing = "#{DmsfFile.storage_path}/#{rev.disk_filename}"
|
||||
existing = DmsfFile.storage_path.join rev.disk_filename
|
||||
new_path = rev.disk_file
|
||||
begin
|
||||
if File.exist?(existing)
|
||||
@ -142,13 +142,13 @@ class Dmsf144 < ActiveRecord::Migration
|
||||
DmsfFileRevision.visible.each {|rev|
|
||||
next if rev.project.nil?
|
||||
project = rev.project.identifier.gsub(/[^\w\.\-]/,'_')
|
||||
existing = "#{DmsfFile.storage_path}/p_#{project}/#{rev.disk_filename}"
|
||||
new_path = "#{DmsfFile.storage_path}/#{rev.disk_filename}"
|
||||
existing = DmsfFile.storage_path.jopin("p_#{project}/#{rev.disk_filename}")
|
||||
new_path = DmsfFile.storage_path.join(rev.disk_filename)
|
||||
if File.exist?(existing)
|
||||
if File.exist?(new_path)
|
||||
rev.disk_filename = rev.new_storage_filename
|
||||
rev.save!
|
||||
new_path = "#{DmsfFile.storage_path}/#{rev.disk_filename}"
|
||||
new_path = DmsfFile.storage_path.join(rev.disk_filename)
|
||||
end
|
||||
FileUtils.mv(existing, new_path)
|
||||
end
|
||||
|
||||
4
init.rb
4
init.rb
@ -40,8 +40,8 @@ Redmine::Plugin.register :redmine_dmsf do
|
||||
'dmsf_max_file_download' => '0',
|
||||
'dmsf_max_email_filesize' => '0',
|
||||
'dmsf_max_ajax_upload_filesize' => '100',
|
||||
'dmsf_storage_directory' => Rails.root.join('files/dmsf').to_s,
|
||||
'dmsf_index_database' => Rails.root.join('files/dmsf_index').to_s,
|
||||
'dmsf_storage_directory' => 'dmsf',
|
||||
'dmsf_index_database' => 'dmsf_index',
|
||||
'dmsf_stemming_lang' => 'english',
|
||||
'dmsf_stemming_strategy' => 'STEM_NONE',
|
||||
'dmsf_webdav' => '1',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user