diff --git a/app/models/dmsf_file.rb b/app/models/dmsf_file.rb index 6a96ec4b..ef039a86 100644 --- a/app/models/dmsf_file.rb +++ b/app/models/dmsf_file.rb @@ -82,7 +82,7 @@ class DmsfFile < ActiveRecord::Base end def self.project_root_files(project) - visible.where(:dmsf_folder_id => nil, :project_id => project.if).order('name ASC') + visible.where(:project_id => project.id, :dmsf_folder_id => nil).order('name ASC') end def self.find_file_by_name(project, folder, name) diff --git a/app/models/dmsf_file_revision.rb b/app/models/dmsf_file_revision.rb index 8043de2c..281062df 100644 --- a/app/models/dmsf_file_revision.rb +++ b/app/models/dmsf_file_revision.rb @@ -87,6 +87,14 @@ class DmsfFileRevision < ActiveRecord::Base end end + def destroy + if Setting.plugin_redmine_dmsf['dmsf_really_delete_files'] + dependencies = DmsfFileRevision.where(:disk_filename => self.disk_filename).all.count + File.delete(self.disk_file) if dependencies <= 1 && File.exist?(self.disk_file) + end + super + end + # In a static call, we find the first matched record on base object type and # then run the access_grouped call against it def self.access_grouped(revision_id) diff --git a/lib/redmine_dmsf/patches/project_patch.rb b/lib/redmine_dmsf/patches/project_patch.rb index 36bafe05..bd70a4c6 100644 --- a/lib/redmine_dmsf/patches/project_patch.rb +++ b/lib/redmine_dmsf/patches/project_patch.rb @@ -31,9 +31,8 @@ module RedmineDmsf unloadable alias_method_chain :copy, :dmsf - has_many :dmsf_files, :class_name => 'DmsfFile', :foreign_key => 'project_id', :conditions => { :dmsf_folder_id => nil } - #Fix: should only be root folders not, all folders - has_many :dmsf_folders, :class_name => 'DmsfFolder', :foreign_key => 'project_id', :conditions => {:dmsf_folder_id => nil}, :dependent => :destroy + has_many :dmsf_files, :class_name => 'DmsfFile', :foreign_key => 'project_id', :conditions => { :dmsf_folder_id => nil }, :dependent => :destroy + has_many :dmsf_folders, :class_name => 'DmsfFolder', :foreign_key => 'project_id', :conditions => {:dmsf_folder_id => nil}, :dependent => :destroy has_many :dmsf_workflows, :dependent => :destroy end