Skip to content

Commit

Permalink
allow import of one doi by id. datacite/datacite#965
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Dec 21, 2020
1 parent 19446ec commit 02e7ec3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
9 changes: 7 additions & 2 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1206,8 +1206,13 @@ def self.index_one(doi_id: nil)
"Started indexing DOI #{doi.doi}."
end

def self.import_one(doi_id: nil)
doi = Doi.where(doi: doi_id).first
def self.import_one(doi_id: nil, id: nil)
if doi_id
doi = Doi.where(doi: doi_id).first
else
doi = Doi.where(id: id).first
end

if doi.blank?
message = "[MySQL] Error importing DOI #{doi_id}: not found"
Rails.logger.error message
Expand Down
6 changes: 3 additions & 3 deletions lib/tasks/datacite_doi.rake
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ namespace :datacite_doi do

desc "Import one datacite DOI"
task import_one: :environment do
if ENV["DOI"].nil?
puts "ENV['DOI'] is required"
if ENV["DOI"].nil? && ENV["ID"].nil?
puts "Either ENV variable DOI or ID are required"
exit
end

puts DataciteDoi.import_one(doi_id: ENV["DOI"])
puts DataciteDoi.import_one(doi_id: ENV["DOI"], id: ENV["ID"])
end

desc "Index one datacite DOI"
Expand Down
6 changes: 3 additions & 3 deletions lib/tasks/doi.rake
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ namespace :doi do

desc "Import one DOI"
task import_one: :environment do
if ENV["DOI"].nil?
puts "ENV['DOI'] is required"
if ENV["DOI"].nil? && ENV["ID"].nil?
puts "Either ENV variable DOI or ID are required"
exit
end

Doi.import_one(doi_id: ENV["DOI"])
puts Doi.import_one(doi_id: ENV["DOI"], id: ENV["ID"])
end

desc "Trigger DOI import based on query"
Expand Down
6 changes: 3 additions & 3 deletions lib/tasks/other_doi.rake
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ namespace :other_doi do

desc "Import one other DOI"
task import_one: :environment do
if ENV["DOI"].nil?
puts "ENV['DOI'] is required"
if ENV["DOI"].nil? && ENV["ID"].nil?
puts "Either ENV variable DOI or ID are required"
exit
end

puts OtherDoi.import_one(doi_id: ENV["DOI"])
puts OtherDoi.import_one(doi_id: ENV["DOI"], id: ENV["ID"])
end

desc "Index one other DOI"
Expand Down

0 comments on commit 02e7ec3

Please sign in to comment.