Skip to content

Commit

Permalink
check for affiliation type, make sure it is an array. #324
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Aug 1, 2019
1 parent 04e12bd commit ea5e4fd
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit ea5e4fd

Please sign in to comment.