From 75c253453efe0b04ef7eb01776a10e0243ee5880 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Pi=C4=8Dman?= Date: Wed, 27 Mar 2019 12:03:44 +0100 Subject: [PATCH] Failure to Update DMSF from 1.5.9 to 2.0.0 during migrate --- ...0170421101901_dmsf_file_container_rollback.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/db/migrate/20170421101901_dmsf_file_container_rollback.rb b/db/migrate/20170421101901_dmsf_file_container_rollback.rb index ea904047..92dd3738 100644 --- a/db/migrate/20170421101901_dmsf_file_container_rollback.rb +++ b/db/migrate/20170421101901_dmsf_file_container_rollback.rb @@ -44,12 +44,16 @@ class DmsfFileContainerRollback < ActiveRecord::Migration[4.2] new_folder_ids << parent.id end # Issue folder - folder = DmsfFolder.new - folder.project_id = issue.project.id - folder.dmsf_folder_id = parent.id - folder.title = "#{issue.id} - #{DmsfFolder.get_valid_title(issue.subject)}" - folder.user_id = User.anonymous.id - folder.save! + title = "#{issue.id} - #{DmsfFolder.get_valid_title(issue.subject)}" + folder = DmsfFolder.find_by(project_id: issue.project.id, dmsf_folder_id: parent.id, title: title) + unless folder + folder = DmsfFolder.new + folder.project_id = issue.project.id + folder.dmsf_folder_id = parent.id + folder.title = "#{issue.id} - #{DmsfFolder.get_valid_title(issue.subject)}" + folder.user_id = User.anonymous.id + folder.save! + end new_folder_ids << folder.id # Move the file into the new folder file.dmsf_folder_id = folder.id