Skip to content

Commit a1a22f0

Browse files
committed
fixed bug with updating identifiers. added rake task to v3 to fix fundref ids
1 parent d4218cc commit a1a22f0

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

app/controllers/concerns/org_selectable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# \"name\":\"Portland State University (PDX)\",
2929
# \"sort_name\":\"Portland State University\",
3030
# \"ror\":\"https://ror.org/00yn2fy02\",
31-
# \"fundref\":\"https://api.crossref.org/funders/100007083\"
31+
# \"fundref\":\"https://doi.org/10.13039/100007083\"
3232
# }
3333
# }
3434
#

app/models/identifier.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ def value_uniqueness_without_scheme
133133

134134
# Ensure that the identifiable only has one identifier for the scheme
135135
def value_uniqueness_with_scheme
136-
if Identifier.where(identifier_scheme: identifier_scheme,
137-
identifiable: identifiable).any?
136+
if new_record? && Identifier.where(identifier_scheme: identifier_scheme,
137+
identifiable: identifiable).any?
138138
errors.add(:identifier_scheme, _("already assigned a value"))
139139
end
140140
end

lib/tasks/upgrade.rake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ namespace :upgrade do
832832

833833
fundref = IdentifierScheme.find_or_initialize_by(name: "fundref")
834834
fundref.for_orgs = true
835-
fundref.identifier_prefix = "https://api.crossref.org/funders/"
835+
fundref.identifier_prefix = "https://doi.org/10.13039/"
836836
fundref.save
837837
end
838838

@@ -1217,7 +1217,7 @@ namespace :upgrade do
12171217
p " 'University of Somewhere' may match to 'Univerity of Somewhere - Medical Center'"
12181218
p " To correct any issues, please delete/insert/update the corresponding Identifier:"
12191219
p " delete from identifiers where identifiable_type = 'Org' and identifiable_id = [orgs.id];"
1220-
p " insert into identifiers (identifiable_type, identifier_scheme_id, attrs, identifiable_id, value) values ('Org', [identifier_scheme_id], '{}', [orgs.id], 'https://api.crossref.org/funders/0000000000');"
1220+
p " insert into identifiers (identifiable_type, identifier_scheme_id, attrs, identifiable_id, value) values ('Org', [identifier_scheme_id], '{}', [orgs.id], 'https://doi.org/10.13039/0000000000');"
12211221
p " update identifiers set `value` = 'https://ror.org/123456789' where identifiable_id = [orgs.id] and identifier_scheme_id = [identifier_scheme_id] and identifiable_type= 'Org';"
12221222
p "---------------------------------------------------------------"
12231223
end

lib/tasks/v3.rake

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace :v3 do
44
task upgrade_3_0_0: :environment do
55
Rake::Task["v3:ensure_default_languages"].execute
66
Rake::Task["v3:ensure_feedback_defaults"].execute
7+
Rake::Task["v3:fix_funder_ids"].execute
78
end
89

910
# Set any records with a nil `language_id` to the default language
@@ -35,4 +36,24 @@ namespace :v3 do
3536
Org.where(feedback_email_msg: nil).update_all(feedback_email_msg: feedback_confirmation_default_message)
3637
end
3738

39+
# E.G. change 'https://api.crossref.org/funders/100000060' to 'https://doi.org/10.13039/100000060'
40+
desc "Corrects the Crossref funder ids which were originally set to the URL instead of the DOI"
41+
task fix_funder_ids: :environment do
42+
scheme = IdentifierScheme.where(name: "fundref").first
43+
44+
incorrect_prefix = "https://api.crossref.org/funders/"
45+
correct_prefix = "https://doi.org/10.13039/"
46+
47+
if scheme.present?
48+
scheme.update(identifier_prefix: correct_prefix) unless scheme.identifier_prefix == correct_prefix
49+
Identifier.where(identifier_scheme: scheme).each do |id|
50+
next unless id.value.start_with?(incorrect_prefix)
51+
52+
id.update(value: id.value.gsub(incorrect_prefix, correct_prefix))
53+
p "#{id.value} - #{id.valid?}"
54+
p id.errors.full_messages
55+
end
56+
end
57+
end
58+
3859
end

0 commit comments

Comments
 (0)