From ea5e4fd10e2fa6336b1bf29c78df4319351456d1 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Thu, 1 Aug 2019 17:57:29 +0200 Subject: [PATCH] check for affiliation type, make sure it is an array. #324 --- app/models/doi.rb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/app/models/doi.rb b/app/models/doi.rb index e444f091a..03c43207f 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -582,16 +582,26 @@ def self.convert_affiliation_by_id(options={}) Doi.where(id: id..(id + 499)).find_each do |doi| should_update = false creators = Array.wrap(doi.creators).map do |c| - if c["affiliation"].is_a?(String) - c["affiliation"] = { "name" => c["affiliation"] } + if c["affiliation"].nil? + c["affiliation"] = [] + elsif c["affiliation"].is_a?(String) + c["affiliation"] = [{ "name" => c["affiliation"] }] + should_update = true + else c["affiliation"].is_a?(Hash) + c["affiliation"] = Array.wrap(c["affiliation"]) should_update = true end c end contributors = Array.wrap(doi.contributors).map do |c| - if c["affiliation"].is_a?(String) - c["affiliation"] = { "name" => c["affiliation"] } + if c["affiliation"].nil? + c["affiliation"] = [] + elsif c["affiliation"].is_a?(String) + c["affiliation"] = [{ "name" => c["affiliation"] }] + should_update = true + else c["affiliation"].is_a?(Hash) + c["affiliation"] = Array.wrap(c["affiliation"]) should_update = true end