Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use OpenILS::Utils::Cronscript;
- use Spreadsheet::Read;
- use List::MoreUtils qw(uniq);
- my $U = 'OpenILS::Application::AppUtils';
- my %defaults = (
- 'username=s' => '',
- 'password=s' => '',
- 'workstation=s' => '',
- 'staff' => 1,
- nolockfile => 1
- );
- my $script = OpenILS::Utils::Cronscript->new(\%defaults);
- my $opts = $script->MyGetOptions();
- my $authtoken = $script->authenticate({
- username => $opts->{username},
- password => $opts->{password},
- workstation => $opts->{workstation},
- staff => $opts->{staff}
- });
- die("Failed to authenticate to Evergreen. Check auth parameters.")
- unless ($authtoken);
- my $book;
- for my $file (@ARGV) {
- if ($book) {
- $book->add($file);
- } else {
- $book = Spreadsheet::Read->new($file);
- }
- }
- # For statistics reporting:
- my $total = 0; # Number of spreadsheet entries.
- my $seen = 0; # Copies found in the database
- my $circs = 0; # Number of open circulations found
- my $checkins = 0; # Number of successful check ins
- my $checkfails = 0; # Number of failed check ins
- my $deleted = 0; # Number of successful deletions
- my $delfails = 0; # Failed deletes
- # Read barcodes from the spreadsheet(s) into a list
- my @barcodes;
- for (my $i = 1; $i <= scalar($book->sheets); $i++) {
- my $sheet = $book->sheet($i);
- my $rows = $sheet->maxrow();
- my $cols = $sheet->maxcol();
- # search the first row of headers for the barcode column
- my ($bcolumn, $bfound);
- for ($bcolumn = 1; $bcolumn <= $cols; $bcolumn++) {
- my $val = $sheet->cell($bcolumn, 1);
- if ($val =~ /^(?:item|copy)? *barcode/i) {
- $bfound = 1;
- last;
- }
- }
- next unless ($bfound);
- for (my $row = 2; $row <= $rows; $row++) {
- my $barcode = $sheet->cell($bcolumn, $row);
- next unless ($barcode);
- push(@barcodes, $barcode);
- }
- }
- # Process said list
- for my $barcode (uniq(sort @barcodes)) {
- $total++;
- my $cstoreses = $script->session('open-ils.cstore');
- my $cstorereq = $cstoreses->request(
- 'open-ils.cstore.direct.asset.copy.search',
- {barcode=>$barcode, deleted=>'f'},
- {flesh=>1, flesh_fields=>{acp=>['circulations']}}
- );
- while (my $cstoreres = $cstorereq->recv(timeout=>600)) {
- my $copy = $cstoreres->content;
- if (ref($copy) eq 'Fieldmapper::asset::copy') {
- $seen++
- }
- }
- $cstorereq->finish();
- $cstoreses->disconnect();
- }
- END {
- $script->logout();
- # Report.
- print <<EREPORT;
- Total Barcodes: $total
- Barcodes Found: $seen
- Total Circs: $circs
- Checkins: $checkins
- Checkin Fails: $checkfails
- Copies Deleted: $deleted
- Failed Deletes: $delfails
- EREPORT
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement