From 4cf5d6bfd12340a13c4bde802aa9eba688289de7 Mon Sep 17 00:00:00 2001 From: Karel Picman Date: Thu, 6 Feb 2014 10:12:28 +0100 Subject: [PATCH] #214 Required DMSF custom field prevents documents to be saved --- app/controllers/dmsf_upload_controller.rb | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/app/controllers/dmsf_upload_controller.rb b/app/controllers/dmsf_upload_controller.rb index fae4eb19..16b66fba 100644 --- a/app/controllers/dmsf_upload_controller.rb +++ b/app/controllers/dmsf_upload_controller.rb @@ -1,6 +1,7 @@ # Redmine plugin for Document Management System "Features" # -# Copyright (C) 2011 Vít Jonáš +# Copyright (C) 2011 Vít Jonáš +# Copyright (C) 2014 Karel Pičman # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -142,7 +143,13 @@ class DmsfUploadController < ApplicationController end # Need to save file first to generate id for it in case of creation. - # File id is needed to properly generate revision disk filename + # File id is needed to properly generate revision disk filename + if commited_file['dmsf_file_revision'].present? + commited_file['dmsf_file_revision']['custom_field_values'].each_with_index do |v, i| + new_revision.custom_field_values[i].value = v[1] + end + end + if new_revision.valid? && file.save new_revision.disk_filename = new_revision.new_storage_filename else @@ -157,15 +164,6 @@ class DmsfUploadController < ApplicationController File.delete(commited_disk_filepath) file.set_last_revision new_revision files.push(file) - if commited_file['dmsf_file_revision'].present? - commited_file['dmsf_file_revision']['custom_field_values'].each do |v| - cv = CustomValue.where(:customized_id => new_revision.id, :custom_field_id => v[0]).first - if cv - cv.value = v[1] - cv.save - end - end - end else failed_uploads.push(commited_file) end