From e70642cd660805a7793aad5302c0b8930bd84533 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Pi=C4=8Dman?= Date: Tue, 6 Jun 2023 13:16:11 +0200 Subject: [PATCH] More robust XML import --- app/models/custom_workflow.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/models/custom_workflow.rb b/app/models/custom_workflow.rb index 20b39e3..44a1c6e 100644 --- a/app/models/custom_workflow.rb +++ b/app/models/custom_workflow.rb @@ -53,10 +53,18 @@ class CustomWorkflow < ApplicationRecord def self.import_from_xml(xml) attributes = Hash.from_xml(xml).values.first + attributes.delete 'id' attributes.delete 'exported_at' attributes.delete 'plugin_version' attributes.delete 'ruby_version' attributes.delete 'rails_version' + name = attributes['name'] + i = 1 + while CustomWorkflow.exists?(name: name) + name = "#{attributes['name']}_#{i}" + i += 1 + end + attributes['name'] = name CustomWorkflow.new attributes end