Control DMSF via REST API #78
This commit is contained in:
parent
76417955eb
commit
c5d279e266
@ -31,6 +31,8 @@ class DmsfController < ApplicationController
|
|||||||
before_filter :authorize
|
before_filter :authorize
|
||||||
before_filter :find_folder, :except => [:new, :create, :edit_root, :save_root]
|
before_filter :find_folder, :except => [:new, :create, :edit_root, :save_root]
|
||||||
before_filter :find_parent, :only => [:new, :create]
|
before_filter :find_parent, :only => [:new, :create]
|
||||||
|
|
||||||
|
accept_api_auth :show, :create
|
||||||
|
|
||||||
helper :all
|
helper :all
|
||||||
|
|
||||||
@ -134,7 +136,14 @@ class DmsfController < ApplicationController
|
|||||||
@trash_enabled = DmsfFolder.deleted.where(:project_id => @project.id).any? ||
|
@trash_enabled = DmsfFolder.deleted.where(:project_id => @project.id).any? ||
|
||||||
DmsfFile.deleted.where(:project_id => @project.id).any? ||
|
DmsfFile.deleted.where(:project_id => @project.id).any? ||
|
||||||
DmsfLink.deleted.where(:project_id => @project.id).any?
|
DmsfLink.deleted.where(:project_id => @project.id).any?
|
||||||
end
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html {
|
||||||
|
render :layout => !request.xhr?
|
||||||
|
}
|
||||||
|
format.api
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def trash
|
def trash
|
||||||
@folder_manipulation_allowed = User.current.allowed_to? :folder_manipulation, @project
|
@folder_manipulation_allowed = User.current.allowed_to? :folder_manipulation, @project
|
||||||
@ -249,13 +258,11 @@ class DmsfController < ApplicationController
|
|||||||
render :action => 'edit'
|
render :action => 'edit'
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
if (Rails::VERSION::MAJOR > 3)
|
@folder = DmsfFolder.new
|
||||||
@folder = DmsfFolder.new(
|
@folder.title = params[:dmsf_folder][:title]
|
||||||
params.require(:dmsf_folder).permit(:title, :description, :dmsf_folder_id))
|
@folder.description = params[:dmsf_folder][:description]
|
||||||
else
|
@folder.dmsf_folder_id = params[:dmsf_folder][:dmsf_folder_id]
|
||||||
@folder = DmsfFolder.new(params[:dmsf_folder])
|
|
||||||
end
|
|
||||||
@folder.project = @project
|
@folder.project = @project
|
||||||
@folder.user = User.current
|
@folder.user = User.current
|
||||||
|
|
||||||
|
|||||||
@ -26,10 +26,12 @@ class DmsfUploadController < ApplicationController
|
|||||||
|
|
||||||
before_filter :find_project
|
before_filter :find_project
|
||||||
before_filter :authorize
|
before_filter :authorize
|
||||||
before_filter :find_folder, :except => [:upload_file]
|
before_filter :find_folder, :except => [:upload_file, :upload]
|
||||||
|
|
||||||
helper :all
|
helper :all
|
||||||
helper :dmsf_workflows
|
helper :dmsf_workflows
|
||||||
|
|
||||||
|
accept_api_auth :upload, :commit
|
||||||
|
|
||||||
def upload_files
|
def upload_files
|
||||||
uploaded_files = params[:attachments]
|
uploaded_files = params[:attachments]
|
||||||
@ -62,11 +64,7 @@ class DmsfUploadController < ApplicationController
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
@disk_filename = DmsfHelper.temp_filename(@tempfile.original_filename)
|
@disk_filename = DmsfHelper.temp_filename(@tempfile.original_filename)
|
||||||
File.open("#{DmsfHelper.temp_dir}/#{@disk_filename}", 'wb') do |f|
|
FileUtils.mv(@tempfile.path, "#{DmsfHelper.temp_dir}/#{@disk_filename}")
|
||||||
while (buffer = @tempfile.read(8192))
|
|
||||||
f.write(buffer)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if File.size("#{DmsfHelper.temp_dir}/#{@disk_filename}") <= 0
|
if File.size("#{DmsfHelper.temp_dir}/#{@disk_filename}") <= 0
|
||||||
begin
|
begin
|
||||||
File.delete("#{DmsfHelper.temp_dir}/#{@disk_filename}")
|
File.delete("#{DmsfHelper.temp_dir}/#{@disk_filename}")
|
||||||
@ -85,12 +83,55 @@ class DmsfUploadController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# REST API document upload
|
||||||
|
def upload
|
||||||
|
unless request.content_type == 'application/octet-stream'
|
||||||
|
render :nothing => true, :status => 406
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
@attachment = Attachment.new(:file => request.raw_post)
|
||||||
|
@attachment.author = User.current
|
||||||
|
@attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16)
|
||||||
|
saved = @attachment.save
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.js
|
||||||
|
format.api {
|
||||||
|
if saved
|
||||||
|
render :action => 'upload', :status => :created
|
||||||
|
else
|
||||||
|
render_validation_errors(@attachment)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def commit_files
|
def commit_files
|
||||||
if (Rails::VERSION::MAJOR > 3)
|
if (Rails::VERSION::MAJOR > 3)
|
||||||
commited_files = params.require(:commited_files)
|
commited_files = params.require(:commited_files)
|
||||||
else
|
else
|
||||||
commited_files = params[:commited_files]
|
commited_files = params[:commited_files]
|
||||||
end
|
end
|
||||||
|
commit_files_internal commited_files
|
||||||
|
end
|
||||||
|
|
||||||
|
# REST API file commit
|
||||||
|
def commit
|
||||||
|
uploaded_files = params[:attachments]
|
||||||
|
if uploaded_files && uploaded_files.is_a?(Hash)
|
||||||
|
# standard file input uploads
|
||||||
|
uploaded_files.each_value do |uploaded_file|
|
||||||
|
upload = DmsfUpload.create_from_uploaded_attachment(@project, @folder, uploaded_file)
|
||||||
|
uploaded_file[:disk_filename] = upload.disk_filename
|
||||||
|
end
|
||||||
|
end
|
||||||
|
commit_files_internal uploaded_files
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def commit_files_internal(commited_files)
|
||||||
if commited_files && commited_files.is_a?(Hash)
|
if commited_files && commited_files.is_a?(Hash)
|
||||||
files = []
|
files = []
|
||||||
failed_uploads = []
|
failed_uploads = []
|
||||||
@ -146,12 +187,12 @@ class DmsfUploadController < ApplicationController
|
|||||||
new_revision.mime_type = Redmine::MimeType.of(new_revision.name)
|
new_revision.mime_type = Redmine::MimeType.of(new_revision.name)
|
||||||
new_revision.size = File.size(commited_disk_filepath)
|
new_revision.size = File.size(commited_disk_filepath)
|
||||||
|
|
||||||
file_upload = File.new(commited_disk_filepath, 'rb')
|
# file_upload = File.new(commited_disk_filepath, 'rb')
|
||||||
unless file_upload
|
# unless file_upload
|
||||||
failed_uploads.push(commited_file)
|
# failed_uploads.push(commited_file)
|
||||||
flash[:error] = l(:error_file_commit_require_uploaded_file)
|
# flash[:error] = l(:error_file_commit_require_uploaded_file)
|
||||||
next
|
# next
|
||||||
end
|
# end
|
||||||
|
|
||||||
if file.locked?
|
if file.locked?
|
||||||
begin
|
begin
|
||||||
@ -180,9 +221,10 @@ class DmsfUploadController < ApplicationController
|
|||||||
|
|
||||||
if new_revision.save
|
if new_revision.save
|
||||||
new_revision.assign_workflow(commited_file[:dmsf_workflow_id])
|
new_revision.assign_workflow(commited_file[:dmsf_workflow_id])
|
||||||
new_revision.copy_file_content(file_upload)
|
#new_revision.copy_file_content(file_upload)
|
||||||
file_upload.close
|
#file_upload.close
|
||||||
File.delete(commited_disk_filepath)
|
#File.delete(commited_disk_filepath)
|
||||||
|
FileUtils.mv(commited_disk_filepath, new_revision.disk_file)
|
||||||
file.set_last_revision new_revision
|
file.set_last_revision new_revision
|
||||||
files.push(file)
|
files.push(file)
|
||||||
else
|
else
|
||||||
@ -213,10 +255,13 @@ class DmsfUploadController < ApplicationController
|
|||||||
flash[:warning] = l(:warning_some_files_were_not_commited, :files => failed_uploads.map{|u| u['name']}.join(', '))
|
flash[:warning] = l(:warning_some_files_were_not_commited, :files => failed_uploads.map{|u| u['name']}.join(', '))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
redirect_to dmsf_folder_path(:id => @project, :folder_id => @folder)
|
respond_to do |format|
|
||||||
|
format.js
|
||||||
|
format.api { render_validation_errors(failed_uploads) }
|
||||||
|
format.html { redirect_to dmsf_folder_path(:id => @project, :folder_id => @folder) }
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def log_activity(file, action)
|
def log_activity(file, action)
|
||||||
Rails.logger.info "#{Time.now.strftime('%Y-%m-%d %H:%M:%S')} #{User.current.login}@#{request.remote_ip}/#{request.env['HTTP_X_FORWARDED_FOR']}: #{action} dmsf://#{file.project.identifier}/#{file.id}/#{file.last_revision.id}"
|
Rails.logger.info "#{Time.now.strftime('%Y-%m-%d %H:%M:%S')} #{User.current.login}@#{request.remote_ip}/#{request.env['HTTP_X_FORWARDED_FOR']}: #{action} dmsf://#{file.project.identifier}/#{file.id}/#{file.last_revision.id}"
|
||||||
|
|||||||
@ -45,13 +45,7 @@ class DmsfUpload
|
|||||||
:original_filename => a.filename,
|
:original_filename => a.filename,
|
||||||
:comment => uploaded_file[:description]
|
:comment => uploaded_file[:description]
|
||||||
}
|
}
|
||||||
File.open(a.diskfile, 'rb') do |fr|
|
FileUtils.mv(a.diskfile, "#{DmsfHelper.temp_dir}/#{uploaded[:disk_filename]}")
|
||||||
File.open("#{DmsfHelper.temp_dir}/#{uploaded[:disk_filename]}", 'wb') do |fw|
|
|
||||||
while (buffer = fr.read(8192))
|
|
||||||
fw.write(buffer)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
a.destroy
|
a.destroy
|
||||||
DmsfUpload.new(project, folder, uploaded)
|
DmsfUpload.new(project, folder, uploaded)
|
||||||
end
|
end
|
||||||
|
|||||||
30
app/views/dmsf/show.api.rsb
Normal file
30
app/views/dmsf/show.api.rsb
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
api.array :dmsf_folders, api_meta(:total_count => @subfolders.size) do
|
||||||
|
@subfolders.each do |folder|
|
||||||
|
api.folder do
|
||||||
|
api.id folder.id
|
||||||
|
api.title folder.title
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
api.array :dmsf_files, api_meta(:total_count => @files.size) do
|
||||||
|
@files.each do |file|
|
||||||
|
api.file do
|
||||||
|
api.id file.id
|
||||||
|
api.name file.name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
api.array :dmsf_links, api_meta(:total_count => @dir_links.size + @file_links.size + @url_links.size) do
|
||||||
|
(@dir_links + @file_links + @url_links).each do |link|
|
||||||
|
api.link do
|
||||||
|
api.id link.id
|
||||||
|
api.name link.name
|
||||||
|
api.target_type link.target_type
|
||||||
|
api.target_id link.target_id
|
||||||
|
api.target_project_id link.target_project_id
|
||||||
|
api.external_url link.external_url if link.external_url.present?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -1,8 +1,8 @@
|
|||||||
api.file do
|
api.file do
|
||||||
api.id @file.id
|
api.id @file.id
|
||||||
api.name @file.name
|
api.name @file.name
|
||||||
api.project_id @file.project_id
|
api.project_id @file.project_id
|
||||||
api.dmsf_folder_id @file.folder ? @file.dmsf_folder_id : -1
|
api.dmsf_folder_id @file.folder if @file.dmsf_folder_id
|
||||||
api.version "#{@file.last_revision.major_version}.#{@file.last_revision.minor_version}"
|
api.version "#{@file.last_revision.major_version}.#{@file.last_revision.minor_version}" if @file.last_revision
|
||||||
api.content_url url_for(:controller => :dmsf_files, :action => 'show', :download => '', :id => @file, :only_path => false)
|
api.content_url url_for(:controller => :dmsf_files, :action => 'show', :download => '', :id => @file, :only_path => false)
|
||||||
end
|
end
|
||||||
3
app/views/dmsf_upload/commit.api.rsb
Normal file
3
app/views/dmsf_upload/commit.api.rsb
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
api.commit do
|
||||||
|
puts 'OK'
|
||||||
|
end
|
||||||
3
app/views/dmsf_upload/upload.api.rsb
Normal file
3
app/views/dmsf_upload/upload.api.rsb
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
api.upload do
|
||||||
|
api.token @attachment.token
|
||||||
|
end
|
||||||
@ -58,7 +58,9 @@ RedmineApp::Application.routes.draw do
|
|||||||
|
|
||||||
post '/projects/:id/dmsf/upload/files', :controller => 'dmsf_upload', :action => 'upload_files'
|
post '/projects/:id/dmsf/upload/files', :controller => 'dmsf_upload', :action => 'upload_files'
|
||||||
post '/projects/:id/dmsf/upload/file', :controller => 'dmsf_upload', :action => 'upload_file'
|
post '/projects/:id/dmsf/upload/file', :controller => 'dmsf_upload', :action => 'upload_file'
|
||||||
|
post '/projects/:id/dmsf/upload', :controller => 'dmsf_upload', :action => 'upload'
|
||||||
post '/projects/:id/dmsf/upload/commit', :controller => 'dmsf_upload', :action => 'commit_files'
|
post '/projects/:id/dmsf/upload/commit', :controller => 'dmsf_upload', :action => 'commit_files'
|
||||||
|
post '/projects/:id/dmsf/commit', :controller => 'dmsf_upload', :action => 'commit'
|
||||||
|
|
||||||
#
|
#
|
||||||
# dmsf_files controller
|
# dmsf_files controller
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# encoding: utf-8
|
||||||
|
#
|
||||||
# Redmine plugin for Document Management System "Features"
|
# Redmine plugin for Document Management System "Features"
|
||||||
#
|
#
|
||||||
# Copyright (C) 2011-15 Karel Pičman <karel.picman@kontron.com>
|
# Copyright (C) 2011-15 Karel Pičman <karel.picman@kontron.com>
|
||||||
@ -19,22 +21,25 @@
|
|||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
require 'active_resource'
|
require 'active_resource'
|
||||||
|
|
||||||
|
# Simple REST API client in Ruby
|
||||||
|
# usage: ruby api_client.rb [login] [password]
|
||||||
|
|
||||||
# Dmsf file
|
# Dmsf file
|
||||||
class DmsfFile < ActiveResource::Base
|
class DmsfFile < ActiveResource::Base
|
||||||
self.site = 'http://localhost:3000/'
|
self.site = 'http://localhost:3000/'
|
||||||
self.user = 'kpicman'
|
self.user = ARGV[0]
|
||||||
self.password = 'Kontron2014+'
|
self.password = ARGV[1]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Retrieving a file
|
# 2. Get a document
|
||||||
file = DmsfFile.find 17200
|
FILE_ID = 17216
|
||||||
|
file = DmsfFile.find FILE_ID
|
||||||
if file
|
if file
|
||||||
puts file.id
|
puts file.id
|
||||||
puts file.name
|
puts file.name
|
||||||
puts file.version
|
puts file.version
|
||||||
puts file.project_id
|
puts file.project_id
|
||||||
puts file.dmsf_folder_id
|
|
||||||
puts file.content_url
|
puts file.content_url
|
||||||
else
|
else
|
||||||
puts 'No file with id = 1 found'
|
puts "No file with id = #{FILE_ID} found"
|
||||||
end
|
end
|
||||||
42
extra/api/api_client.sh
Normal file
42
extra/api/api_client.sh
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
# encoding: utf-8
|
||||||
|
#
|
||||||
|
# Redmine plugin for Document Management System "Features"
|
||||||
|
#
|
||||||
|
# Copyright (C) 2011-15 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
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Authentication as input parameters either as login + password or the API key
|
||||||
|
# -u ${1}:${2}
|
||||||
|
# -H "X-Redmine-API-Key: ${1}"
|
||||||
|
|
||||||
|
# BOTH XML and JSON formats are supported.
|
||||||
|
# Just replace .xml with .json
|
||||||
|
|
||||||
|
# 1. List of documents in a given folder or the root folder
|
||||||
|
curl -v -H "Content-Type: application/xml" -X GET -u ${1}:${2} http://localhost:3000//projects/12/dmsf.xml
|
||||||
|
#curl -v -H "Content-Type: application/xml" -X GET -u ${1}:${2} http://localhost:3000//projects/12/dmsf.xml?folder_id=5155
|
||||||
|
|
||||||
|
# 2. Get a document
|
||||||
|
#curl -v -H "Content-Type: application/xml" -X GET -u ${1}:${2} http://localhost:3000/dmsf/files/17216.xml
|
||||||
|
|
||||||
|
# 3. Create a folder
|
||||||
|
#curl -v -H "Content-Type: application/xml" -X POST --data "@folder.xml" -u ${1}:${2} http://localhost:3000//projects/12/dmsf/create.xml
|
||||||
|
|
||||||
|
# 4. Upload a document into a given folder or the root folder
|
||||||
|
#curl --data-binary "@cat.gif" -H "Content-Type: application/octet-stream" -X POST -u ${1}:${2} http://localhost:3000//projects/12/dmsf/upload.xml?filename=cat.gif
|
||||||
|
#curl -v -H "Content-Type: application/xml" -X POST --data "@file.xml" -u ${1}:${2} http://localhost:3000//projects/12/dmsf/commit.xml
|
||||||
BIN
extra/api/cat.gif
Normal file
BIN
extra/api/cat.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.7 KiB |
12
extra/api/file.xml
Normal file
12
extra/api/file.xml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf8" ?>
|
||||||
|
<attachments>
|
||||||
|
<uploaded_file>
|
||||||
|
<disk_filename>cat.gif</disk_filename>
|
||||||
|
<name>cat.gif</name>
|
||||||
|
<title>cat.gif</title>
|
||||||
|
<description>REST API</description>
|
||||||
|
<comment>From API</comment>
|
||||||
|
<version/>
|
||||||
|
<token>15843.c49f68ff81b552d315927df2e27df506</token>
|
||||||
|
</uploaded_file>
|
||||||
|
</attachments>
|
||||||
6
extra/api/folder.xml
Normal file
6
extra/api/folder.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<dmsf_folder>
|
||||||
|
<title>rest_api</title>
|
||||||
|
<description>A folder created via REST API</description>
|
||||||
|
<dmsf_folder_id/>
|
||||||
|
</dmsf_folder>
|
||||||
4
init.rb
4
init.rb
@ -28,7 +28,7 @@ Redmine::Plugin.register :redmine_dmsf do
|
|||||||
name 'DMSF'
|
name 'DMSF'
|
||||||
author 'Vit Jonas / Daniel Munn / Karel Picman'
|
author 'Vit Jonas / Daniel Munn / Karel Picman'
|
||||||
description 'Document Management System Features'
|
description 'Document Management System Features'
|
||||||
version '1.5.1 stable'
|
version '1.5.2 devel'
|
||||||
url 'http://www.redmine.org/plugins/dmsf'
|
url 'http://www.redmine.org/plugins/dmsf'
|
||||||
author_url 'https://github.com/danmunn/redmine_dmsf/graphs/contributors'
|
author_url 'https://github.com/danmunn/redmine_dmsf/graphs/contributors'
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ Redmine::Plugin.register :redmine_dmsf do
|
|||||||
{:dmsf => [:new, :create, :delete, :edit, :save, :edit_root, :save_root, :lock, :unlock, :notify_activate, :notify_deactivate, :restore]}
|
{:dmsf => [:new, :create, :delete, :edit, :save, :edit_root, :save_root, :lock, :unlock, :notify_activate, :notify_deactivate, :restore]}
|
||||||
permission :file_manipulation,
|
permission :file_manipulation,
|
||||||
{:dmsf_files => [:create_revision, :lock, :unlock, :delete_revision, :notify_activate, :notify_deactivate, :restore],
|
{:dmsf_files => [:create_revision, :lock, :unlock, :delete_revision, :notify_activate, :notify_deactivate, :restore],
|
||||||
:dmsf_upload => [:upload_files, :upload_file, :commit_files],
|
:dmsf_upload => [:upload_files, :upload_file, :upload, :commit_files, :commit],
|
||||||
:dmsf_links => [:new, :create, :destroy, :restore]
|
:dmsf_links => [:new, :create, :destroy, :restore]
|
||||||
}
|
}
|
||||||
permission :file_delete,
|
permission :file_delete,
|
||||||
|
|||||||
@ -78,7 +78,7 @@ module RedmineDmsf
|
|||||||
'-',
|
'-',
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
] + entities if parent?
|
] + entities if parent
|
||||||
@response.body << index_page % [ path.empty? ? '/' : path, path.empty? ? '/' : path , entities ]
|
@response.body << index_page % [ path.empty? ? '/' : path, path.empty? ? '/' : path , entities ]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -141,19 +141,12 @@ class DmsfConvertDocuments
|
|||||||
revision.comment = 'Converted from documents'
|
revision.comment = 'Converted from documents'
|
||||||
revision.mime_type = attachment.content_type
|
revision.mime_type = attachment.content_type
|
||||||
|
|
||||||
revision.disk_filename = revision.new_storage_filename
|
revision.disk_filename = revision.new_storage_filename
|
||||||
attachment_file = File.open(attachment.diskfile, 'rb')
|
|
||||||
|
|
||||||
unless dry
|
unless dry
|
||||||
File.open(revision.disk_file, 'wb') do |f|
|
FileUtils.cp(attachment.diskfile, revision.disk_file)
|
||||||
while (buffer = attachment_file.read(8192))
|
|
||||||
f.write(buffer)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
revision.size = File.size(revision.disk_file)
|
revision.size = File.size(revision.disk_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
attachment_file.close
|
|
||||||
|
|
||||||
if dry
|
if dry
|
||||||
puts "Dry check revision: #{revision.title}"
|
puts "Dry check revision: #{revision.title}"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user