diff --git a/app/models/doi.rb b/app/models/doi.rb index 5eb4f15e6..80823a204 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -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 diff --git a/lib/tasks/datacite_doi.rake b/lib/tasks/datacite_doi.rake index a4a4ee4c2..4207bbd6d 100644 --- a/lib/tasks/datacite_doi.rake +++ b/lib/tasks/datacite_doi.rake @@ -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" diff --git a/lib/tasks/doi.rake b/lib/tasks/doi.rake index c1f73220c..9a0890a61 100644 --- a/lib/tasks/doi.rake +++ b/lib/tasks/doi.rake @@ -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" diff --git a/lib/tasks/other_doi.rake b/lib/tasks/other_doi.rake index a7ee82466..7f9e02354 100644 --- a/lib/tasks/other_doi.rake +++ b/lib/tasks/other_doi.rake @@ -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"