From dc0c4f80d49a3197a913f365a61e2d853b14fc2e Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Wed, 3 Jun 2020 17:27:12 +0200 Subject: [PATCH] fix repair landing page rake task --- app/models/doi.rb | 17 ++++++++--------- lib/tasks/doi.rake | 6 +++--- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/app/models/doi.rb b/app/models/doi.rb index 4520c2a23..a08eb3d29 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -1853,7 +1853,7 @@ def self.transfer(options={}) Rails.logger.info "[Transfer] Transferring #{response.results.results.length} DOIs starting with _id #{response.results.to_a.first[:_id]}." cursor = response.results.to_a.last[:sort] - Rails.logger.info "[Transfer] Next cursor for transfer is #{cursor.inspect}." + response.results.results.each do |d| TransferJob.perform_later(d.doi, client_target_id: options[:client_target_id]) end @@ -1911,15 +1911,15 @@ def set_defaults self.updated = Time.zone.now.utc.iso8601 end - def self.repair_landing_page(doi_id) - if doi_id.blank? - Rails.logger.error "[Error] No DOI provided." + def self.repair_landing_page(id: nil) + if id.blank? + Rails.logger.error "[Error] No id provided." return nil end - doi = Doi.where(doi: doi_id).first + doi = Doi.where(id: id).first if doi.nil? - Rails.logger.error "[Error] DOI " + doi_id + " not found." + Rails.logger.error "[Error] DOI with #{id} not found." return nil end @@ -1938,10 +1938,9 @@ def self.repair_landing_page(doi_id) # Update with changes doi.update_columns("landing_page": landing_page) - Rails.logger.info "Updated landing page data for DOI: " + doi.doi - + Rails.logger.info "Updated landing page data for DOI " + doi.doi rescue TypeError, NoMethodError => error - Rails.logger.error "Error updating landing page data: " + doi.doi + " - " + error.message + Rails.logger.error "Error updating landing page data for DOI " + doi.doi + " - " + error.message end end diff --git a/lib/tasks/doi.rake b/lib/tasks/doi.rake index 76611e8e8..6e40a44d2 100644 --- a/lib/tasks/doi.rake +++ b/lib/tasks/doi.rake @@ -124,12 +124,12 @@ namespace :doi do desc 'Perform repairs on landing page data for specific DOI' task :repair_landing_page => :environment do - if ENV['DOI'].nil? - puts "ENV['DOI'] is required" + if ENV['ID'].nil? + puts "ENV['ID'] is required" exit end - Doi.repair_landing_page(doi: ENV['DOI']) + Doi.repair_landing_page(id: ENV['ID']) end desc 'Delete dois by a prefix'