Skip to content

Commit

Permalink
Report about druids lacking a public json record in purl-fetcher's db (
Browse files Browse the repository at this point in the history
…#5182)

* Report on druids lacking public cocina
  • Loading branch information
lwrubel authored Oct 16, 2024
1 parent f95dbc3 commit a2ba87e
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions app/reports/publish_status.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

# Exports publish information about druids lacking public cocina.
# https://github.com/sul-dlss/dor-services-app/issues/5181
# Input is a CSV of druids generated on purl-fetcher with the query:
# Purl.status('public').where.missing(:public_json).pluck(:druid)
# Invoke via:
# bin/rails r -e production "PublishStatus.report('druids.csv')"
class PublishStatus
def self.report(druids_file)
druids = File.readlines(druids_file).map(&:strip)
output_file = 'tmp/publish_status_report.csv'

CSV.open(output_file, 'w') do |csv|
csv << %w[druid closed publishable not_dark first_published]

druids.each do |druid|
object = RepositoryObject.find_by(external_identifier: druid)
latest = object.head_version
not_dark = latest.access.fetch('view') != 'dark'

milestones = workflow_client.milestones(druid:)
# to determine if this was published before versioning changes took effect, get the date of the first published milestone
published = milestones.filter { |milestone| milestone[:version] == '1' && milestone[:milestone] == 'published' }
date = published.first[:at] if published.any?

csv << [druid, object.closed?, object.publishable?, not_dark, date]
end
puts "Report written to #{output_file}"
end
end

def self.workflow_client
@workflow_client ||= WorkflowClientFactory.build
end
end

0 comments on commit a2ba87e

Please sign in to comment.