Copy symbolic links also in the root folder

This commit is contained in:
Karel Picman 2014-03-14 14:49:27 +01:00
parent 68dd2e4c83
commit 7193e37d17
5 changed files with 29 additions and 31 deletions

View File

@ -1,6 +1,7 @@
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2011-14 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -81,10 +82,6 @@ class DmsfFile < ActiveRecord::Base
@@storage_path = obj
end
def self.project_root_files(project)
visible.where(:project_id => project.id, :dmsf_folder_id => nil).order('name ASC')
end
def self.find_file_by_name(project, folder, name)
where(
:project_id => project,

View File

@ -74,10 +74,6 @@ class DmsfFolder < ActiveRecord::Base
return true
end
def self.project_root_folders(project)
visible.where(:project_id => project.id, :dmsf_folder_id => nil, ).order('title ASC').all
end
def self.find_by_title(project, folder, title)
if folder
visible.where(:project_id => project.id, :dmsf_folder_id => nil, :title => title).first
@ -132,7 +128,7 @@ class DmsfFolder < ActiveRecord::Base
def self.directory_tree(project, current_folder = nil)
tree = [[l(:link_documents), nil]]
DmsfFolder.visible.project_root_folders(project).each do |folder|
project.dmsf_folders.visible.each do |folder|
unless folder == current_folder
tree.push(["...#{folder.title}", folder.id])
directory_subtree(tree, folder, 2, current_folder)

View File

@ -92,7 +92,7 @@ class DmsfLink < ActiveRecord::Base
:target_type => self.target_type,
:name => self.name,
:project_id => project.id,
:dmsf_folder_id => folder.id)
:dmsf_folder_id => folder ? folder.id : nil)
link.save
link
end

View File

@ -1,8 +1,8 @@
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2012 Daniel Munn <dan.munn@munnster.co.uk>
# Copyright (C) 2013 Karel Pičman <karel.picman@kontron.com>
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2012 Daniel Munn <dan.munn@munnster.co.uk>
# Copyright (C) 2011-14 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -25,8 +25,7 @@ module RedmineDmsf
module ProjectPatch
def self.included(base) # :nodoc:
base.send(:include, InstanceMethods)
base.extend(ClassMethods)
base.send(:include, InstanceMethods)
base.class_eval do
unloadable
alias_method_chain :copy, :dmsf
@ -43,19 +42,18 @@ module RedmineDmsf
:conditions => { :dmsf_folder_id => nil, :target_type => DmsfFile.model_name },
:dependent => :destroy
end
end
module ClassMethods
end
module InstanceMethods
def dmsf_count
file_count = DmsfFile.visible.project_root_files(self).count
folder_count = DmsfFolder.visible.project_root_folders(self).count
DmsfFolder.visible.project_root_folders(self).each {|rootfld| file_count += rootfld.deep_file_count; folder_count += rootfld.deep_folder_count }
{:files => file_count, :folders => folder_count}
file_count = self.dmsf_files.visible.count
folder_count = self.dmsf_folders.visible.count
self.dmsf_folders.visible.each do |f|
file_count += f.deep_file_count
folder_count += f.deep_folder_count
end
{ :files => file_count, :folders => folder_count }
end
def copy_with_dmsf(project, options={})
@ -77,19 +75,26 @@ module RedmineDmsf
# Simple yet effective approach to copying things
def copy_dmsf(project)
DmsfFile.visible.project_root_files(project).each {|f|
project.dmsf_folders.visible.each do |f|
f.copy_to(self, nil)
}
DmsfFolder.visible.project_root_folders(project).each {|f|
end
project.dmsf_files.visible.each do |f|
f.copy_to(self, nil)
}
end
project.folder_links.visible.each do |l|
l.copy_to(self, nil)
end
project.file_links.visible.each do |l|
l.copy_to(self, nil)
end
end
end
end
end
end
#Apply patch
# Apply patch
Rails.configuration.to_prepare do
unless Project.included_modules.include?(RedmineDmsf::Patches::ProjectPatch)
Project.send(:include, RedmineDmsf::Patches::ProjectPatch)

View File

@ -73,7 +73,7 @@ class DmsfWebdavIntegrationTest < RedmineDmsf::Test::IntegrationTest
file = DmsfFile.find_file_by_name(project, nil, "test.txt")
assert !file.nil?, 'File test.txt is expected to exist'
assert_difference('DmsfFile.project_root_files(project).length', -1) do
assert_difference('project.dmsf_files.count', -1) do
delete "dmsf/webdav/#{project.identifier}/test.txt", nil, @admin
assert_response :success #If its in the 20x range it's acceptable, should be 204
end