Skip to content

Commit

Permalink
fix repair landing page rake task
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jun 3, 2020
1 parent e8784b0 commit dc0c4f8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
17 changes: 8 additions & 9 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions lib/tasks/doi.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit dc0c4f8

Please sign in to comment.