Document export rake task #634

This commit is contained in:
Karel Picman 2017-01-16 09:37:06 +01:00
parent eb87b50159
commit 2e2b15c260
2 changed files with 82 additions and 0 deletions

View File

@ -507,4 +507,30 @@ class DmsfFile < ActiveRecord::Base
end end
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 end

View File

@ -0,0 +1,56 @@
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011-17 Karel Picman <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
# 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