-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Report about druids lacking a public json record in purl-fetcher's db (…
…#5182) * Report on druids lacking public cocina
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |