#!/usr/bin/perl

$url = `cat /opt/folio/config/url`; chomp($url);
$headers = `cat /opt/folio/config/headers`; chomp($headers);

use DateTime; $dt = DateTime->now; $thisMonth = $dt->month; $thisYear = $dt->year();
use DBI; $dbh = DBI->connect("DBI:mysql:database=discardItems;host=localhost","username","password") or error_exit($DBI::errstr);
use JSON; 

use CGI; $query = new CGI; 
$barcode = $query->param("barcode");
$callNumber = $query->param("callNumber");
$holdingsRecordId = $query->param("holdingsRecordId");
$instanceId = $query->param("instanceId");
$mtype = $query->param("mtype");
$oclc = $query->param("oclc");
$title = $query->param("title");
$username = $query->param("username");
if (length($thisMonth) == 1) {$thisMonth = "0" . $thisMonth;}
$yyyymm = $thisYear . $thisMonth;

$insert = $dbh->prepare("insert into log (oclc,title,callNumber,mtype,barcode,instanceId,xUser,yyyymm) values (?,?,?,?,?,?,?,?)");
$insert->execute($oclc,$title,$callNumber,$mtype,$barcode,$instanceId,$username,$yyyymm);
$insert->finish();

$items = `curl -s -X GET $headers $url/item-storage/items?query=holdingsRecordId=$holdingsRecordId`;
$hash = decode_json $items;
$totalItemsFound = $hash->{totalRecords};
for ( @{$hash->{items}} ) {
    $itemId = $_->{'id'};
    $thisBarcode = $_->{'barcode'};
    if ($thisBarcode eq $barcode) {$deleteItem = `curl -s -X DELETE $headers $url/item-storage/items/$itemId`;}
}
if ($totalItemsFound == 1) {
    $deleteHoldingsRecord = `curl -s -X DELETE $headers $url/holdings-storage/holdings/$holdingsRecordId`;
    $getHoldingsRecords = `curl -s -X GET -G $headers -d 'limit=0' $url/holdings-storage/holdings?query=instanceId==$instanceId`;
    $hash = decode_json $getHoldingsRecords;
    $totalRecords = $hash->{'totalRecords'};
    if ($totalRecords == 0) {
        $instance = `curl -s -X GET -G $headers $url/instance-storage/instances/$instanceId`;
        $note2self = "the following marks the instance : Suppress from discovery";
        $instance =~ s/"discoverySuppress" : false/"discoverySuppress" : true/;
        $note2self = "the following either replaces or adds the Instance status term : discarded";
        if ($instance =~ /"statusId" : "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"/) {
            $instance =~ s/"statusId" : "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"/"statusId" : "9fa5c0e6-d9c5-4e42-b2f4-ecc607b7f7a5"/;
        } else {
            $instance =~ s/"statusUpdatedDate"/"statusId" : "9fa5c0e6-d9c5-4e42-b2f4-ecc607b7f7a5",\n  "statusUpdatedDate"/;
        }
        $note2self = "the following updates the instance with the above changes";
        $put = `curl -s -X PUT $headers -d '$instance' $url/instance-storage/instances/$instanceId`;
        $note2self = "the following gets the recordId and marks the record : deleted";
        $record = `curl -s -X GET $headers $url/source-storage/records/$instanceId/formatted?idType=INSTANCE`; 
        $hash = decode_json $record; 
        $recordId = $hash->{'id'};
        $delete = `curl -s -X DELETE $headers $url/source-storage/records/$recordId`;
        $insert = $dbh->prepare("insert into removeOCLCholdings (oclc) values (?)");
        $insert->execute($oclc);
        $insert->finish();
    }
}

$dbh->disconnect();


print qq[Content-Type: text/html \n\n 

  <html>
  <body onLoad="document.done.submit();">
  <form action="scanBarcode.pl" method="post" name="done">
  <input name="username" type="hidden" value="$username">
<input name="password" type="hidden" value="passsword">
  </form>
  </body>
  </html>

];

1;
  • No labels

0 Comments

You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account.