diff --git a/app/models/dmsf_file.rb b/app/models/dmsf_file.rb index a11810da..9c2fa413 100644 --- a/app/models/dmsf_file.rb +++ b/app/models/dmsf_file.rb @@ -507,4 +507,30 @@ class DmsfFile < ActiveRecord::Base end end + include ActionView::Helpers::NumberHelper + include Rails.application.routes.url_helpers + + def to_csv + csv = "\"#{self.display_name}\"" + csv << ';' + csv << "\"#{number_to_human_size(self.last_revision.size)}\"" + csv << ';' + csv << "\"#{format_time(self.last_revision.updated_at)}\"" + csv << ';' + csv << "\"#{self.last_revision.version}\"" + csv << ';' + csv << "\"#{self.last_revision.workflow_str(false)}\"" + csv << ';' + csv << "\"#{self.last_revision.user}\"" + csv << ';' + csv << "\"#{self.id}\"" + csv << ';' + csv << "\"r#{self.last_revision.id}\"" + csv << ';' + default_url_options[:host] = Setting.host_name + csv << "\"#{url_for(:controller => :dmsf_files, :action => 'view', :id => self)}\"" + csv << ';' + csv + end + end diff --git a/lib/tasks/dmsf_export.rake b/lib/tasks/dmsf_export.rake new file mode 100644 index 00000000..1b8fc1fc --- /dev/null +++ b/lib/tasks/dmsf_export.rake @@ -0,0 +1,56 @@ +# Redmine plugin for Document Management System "Features" +# +# Copyright (C) 2011-17 Karel Picman +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +desc <<-END_DESC +DMSF export task + * Simply export a folder as CSV + +Available options: + *folder_id - A folder ID + +Example: + rake redmine:dmsf_export folder_id=22682 RAILS_ENV="production" + rake redmine:dmsf_export folder_id=22682 RAILS_ENV="production" 1>data.csv +END_DESC + +namespace :redmine do + task :dmsf_export => :environment do + begin + m = DmsfExport.new + m.export + rescue Exception => e + STDERR.puts e.message + end + end +end + +class DmsfExport + + def initialize + @folder = DmsfFolder.find ENV['folder_id'] + end + + def export + puts "\"Title\";\"Size\";\"Modified\";\"Ver.\";\"Workflow\";\"Author\";\"Doc ID\";\"Active\nDoc\nrevision\";\"URL\"\n" + @folder.dmsf_files.visible.order(:name).each do |f| + puts f.to_csv + puts "\n" + end + end + +end \ No newline at end of file