From ab141df30d21351bff82b960fc73d92d965ec99f Mon Sep 17 00:00:00 2001 From: Moses Hall Date: Thu, 16 Nov 2023 13:34:58 -0500 Subject: [PATCH] DEV-611 Produce a collection report of 1928 items - Adds `pdd_collection_report.pl` which produces a list of YEAR-96 copyright ids. --- bin/pdd_collection_report.pl | 100 +++++++++++++++++++++++++++++++++++ cgi/CRMS.pm | 2 +- 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100755 bin/pdd_collection_report.pl diff --git a/bin/pdd_collection_report.pl b/bin/pdd_collection_report.pl new file mode 100755 index 00000000..8f562c21 --- /dev/null +++ b/bin/pdd_collection_report.pl @@ -0,0 +1,100 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use utf8; +use v5.10; + +BEGIN { + die "SDRROOT environment variable not set" unless defined $ENV{'SDRROOT'}; + use lib $ENV{'SDRROOT'} . '/crms/cgi'; +} + +use Getopt::Long qw(:config no_ignore_case bundling); +use Term::ANSIColor qw(:constants colored); + +use CRMS; + +$Term::ANSIColor::AUTORESET = 1; +binmode(STDOUT, ':encoding(UTF-8)'); +my $usage = < \$help, + 'v+' => \$verbose, + 'y:s' => \$year); + +if ($help) { print $usage. "\n"; exit(0); } + +my $crms = CRMS->new( + verbose => $verbose, + instance => 'production' +); + +$verbose = 0 unless defined $verbose; +print "Verbosity $verbose\n" if $verbose; +$year = $crms->GetTheYear() unless $year; +my $target_date = $year - 96; +print "Using copyright date $target_date from $year\n" if $verbose; + +# First get a hash of all HTIDs with rights attribute {nobody, pd-pvt, supp} +# This so we need not JOIN with CONCAT(rights_current.namespace,".",rights_current.id) +# which really slows things down and is a PITA. +# There should be between 10k and 20k of these excludes. +my $excludes = {}; +my $sql = <<'SQL'; +SELECT CONCAT(rc.namespace,".",rc.id),attr.name FROM rights_current rc +INNER JOIN attributes attr ON rc.attr=attr.id +WHERE attr.name IN ('nobody','pd-pvt','supp') +SQL + +my $ref = $crms->SelectAllSDR($sql); +my $n = scalar @{$ref}; +print "$n results for {nobody, pd-pvt, supp}\n" if $verbose; +foreach my $row (@$ref) { + $excludes->{$row->[0]} = $row->[1]; +} + +# Now get everything from our local bib rights database that has a "date used" of +# YEAR - 96. Print these out in order, excluding anything in the rights exclusion list. +$sql = <<'SQL'; +SELECT id FROM bib_rights_bri +WHERE date_used=? +ORDER BY id +SQL + +$ref = $crms->SelectAll($sql, $target_date); +foreach my $row (@$ref) { + my $htid = $row->[0]; + my $attr = $excludes->{$htid}; + if (defined $attr) { + print RED "Skipping $htid ($attr)\n" if $verbose; + } else { + say $htid; + } +} + +print "Warning: $_\n" for @{$crms->GetErrors()}; diff --git a/cgi/CRMS.pm b/cgi/CRMS.pm index f7ae2776..67b8f8c0 100755 --- a/cgi/CRMS.pm +++ b/cgi/CRMS.pm @@ -65,7 +65,7 @@ sub new return $self; } -our $VERSION = '8.5.18'; +our $VERSION = '8.5.19'; sub Version { return $VERSION;