From b0e4df6a4bb4e4a46b82e25688beef3db2efc59d Mon Sep 17 00:00:00 2001 From: Brian Moses Hall Date: Thu, 14 Mar 2024 12:12:22 -0400 Subject: [PATCH] DEV-1019 Move ht_institutions cron job to OTIS - Remove bin/institutions.pl which will no longer be run. --- bin/institutions.pl | 149 -------------------------------------------- 1 file changed, 149 deletions(-) delete mode 100755 bin/institutions.pl diff --git a/bin/institutions.pl b/bin/institutions.pl deleted file mode 100755 index 005a7777..00000000 --- a/bin/institutions.pl +++ /dev/null @@ -1,149 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; -use utf8; - -BEGIN { - die "SDRROOT environment variable not set" unless defined $ENV{'SDRROOT'}; - use lib $ENV{'SDRROOT'} . '/crms/cgi'; - use lib $ENV{'SDRROOT'} . '/crms/lib'; -} - -use Encode; -use File::Copy; -use Getopt::Long; -use JSON::XS; -use Term::ANSIColor qw(:constants); - -use CRMS; -use CRMS::Cron; -use Utilities; - -$Term::ANSIColor::AUTORESET = 1; - -my $usage = <hathitrust_files_directory - --h Print this help message. --m MAIL Send note to MAIL. May be repeated for multiple recipients. --n No-op; do not send e-mail or move file into hathitrust_files_directory. --p Run in production. --v Emit verbose debugging information. May be repeated. -END - -my $help; -my $instance; -my $nomail; -my @mails; -my $noop; -my $production; -my $verbose = 0; - -Getopt::Long::Configure ('bundling'); -die 'Terminating' unless GetOptions('h|?' => \$help, - 'm:s@' => \@mails, - 'n' => \$noop, - 'p' => \$production, - 'v+' => \$verbose); -$instance = 'production' if $production; -if ($help) { print $usage. "\n"; exit(0); } -print "Verbosity $verbose\n" if $verbose; - -my $crms = CRMS->new( - verbose => $verbose, - instance => $instance -); -my $cron = CRMS::Cron->new(crms => $crms); - -my $outfile_instid = $crms->FSPath('prep', 'ht_institutions.tsv'); -my $outfile_entityid = $crms->FSPath('prep', 'ht_saml_entity_ids.tsv'); -my $msg = $crms->StartHTML(); -$msg .= <<'END'; -

HathiTrust institution report

-

Wrote __N__ records in __OUTFILE_INSTID__, __OUTFILE_ENTITYID__ to -HathiTrust. -

-END - -my $n = CheckInstitutions(); -$msg =~ s/__N__/$n/g; -$msg =~ s/__OUTFILE_INSTID__/$outfile_instid/g; -$msg =~ s/__OUTFILE_ENTITYID__/$outfile_entityid/g; - -if ($noop) { - $crms->set('noop', 1); - print "Noop set: not moving files to new location.\n"; - $msg .= 'Noop set: not moving files to new location.'; -} -else { - eval { - $crms->MoveToHathitrustFiles($outfile_instid, $outfile_entityid); - }; - if ($@) { - $msg .= 'Error moving TSV file: $@'; - } -} -$msg .= "

Warning: $_

\n" for @{$crms->GetErrors()}; -$msg .= ''; - -my $subject = $crms->SubjectLine('HathiTrust Institution Report'); -my $recipients = $cron->recipients(@mails); -my $to = join ',', @$recipients; -if ($noop || scalar @$recipients == 0) -{ - print "No-op or no mails set; not sending e-mail to {$to}\n" if $verbose; - print "$msg\n" if $verbose; -} -else -{ - if (scalar @$recipients > 0) - { - use Encode; - use Mail::Sendmail; - my $bytes = encode('utf8', $msg); - my %mail = ('from' => $crms->GetSystemVar('sender_email'), - 'to' => $to, - 'subject' => $subject, - 'content-type' => 'text/html; charset="UTF-8"', - 'body' => $bytes - ); - sendmail(%mail) || $crms->SetError("Error: $Mail::Sendmail::error\n"); - } -} - -# Returns number of entries written. -sub CheckInstitutions -{ - my $sdr_dbh = $crms->ConnectToSdrDb('ht_repository'); - open my $out_instid, '>:encoding(UTF-8)', $outfile_instid; - open my $out_entityid, '>:encoding(UTF-8)', $outfile_entityid; - my $sql = 'SELECT inst_id,name,entityID,enabled FROM ht_institutions WHERE enabled!=0'. - ' ORDER BY inst_id ASC'; - my $ref; - my $n = 0; - eval { - $ref = $sdr_dbh->selectall_arrayref($sql); - }; - if (defined $ref) - { - $n = scalar @$ref; - foreach my $row (@{$ref}) - { - my ($id,$name,$entityID,$enabled) = @$row; - print $out_instid "$id\t$name\n"; - print $out_entityid "$entityID\t$name\n" if $enabled == 1; - } - } - close $out_instid; - close $out_entityid; - return $n; -} -