Bugzilla – Attachment 130735 Details for
Bug 18618
Mana - Add reading suggestions (crontab and scripts for Koha)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18618: Mana - Add scripts to send readings
Bug-18618-Mana---Add-scripts-to-send-readings.patch (text/plain), 9.30 KB, created by
Marion Durand
on 2022-02-17 13:22:16 UTC
(
hide
)
Description:
Bug 18618: Mana - Add scripts to send readings
Filename:
MIME Type:
Creator:
Marion Durand
Created:
2022-02-17 13:22:16 UTC
Size:
9.30 KB
patch
obsolete
>From 894e58bbe35fe123e24fc09f5b423df3f59a0b5d Mon Sep 17 00:00:00 2001 >From: Baptiste Wojtkowski <baptiste.wojtkowski@biblibre.com> >Date: Thu, 27 Apr 2017 15:44:09 +0000 >Subject: [PATCH] Bug 18618: Mana - Add scripts to send readings > >- There are 2 differents scripts: >misc/cronjobs/mana_send_pairs.pl -> please use it if Mana is installed >misc/cronjobs/mana_send_pairs_without_mana.pl -> designed to work if mana isn't enabled > >- Both of scripts anonymize the datas and send them to mana. >--- > misc/cronjobs/mana_send_pairs.pl | 105 +++++++++++++++++ > misc/cronjobs/mana_send_pairs_without_mana.pl | 106 ++++++++++++++++++ > 2 files changed, 211 insertions(+) > create mode 100644 misc/cronjobs/mana_send_pairs.pl > create mode 100644 misc/cronjobs/mana_send_pairs_without_mana.pl > >diff --git a/misc/cronjobs/mana_send_pairs.pl b/misc/cronjobs/mana_send_pairs.pl >new file mode 100644 >index 0000000000..50ea86b7a8 >--- /dev/null >+++ b/misc/cronjobs/mana_send_pairs.pl >@@ -0,0 +1,105 @@ >+use Modern::Perl; >+ >+use C4::Context; >+use Getopt::Long; >+use Koha; >+use C4::Koha; >+use Koha; >+ >+use JSON; >+use HTTP::Request; >+use Koha::SharedContent; >+ >+my $help = 0; >+my $man = 0; >+my $verbose = 0; >+my $date=DateTime->now()->strftime("%F"); >+ >+print $date; >+ >+ >+GetOptions( >+ 'help|?' => \$help, >+ 'man' => \$man, >+ 'v' => \$verbose, >+ 'date|d:s' => \$date >+); >+ >+ >+$date.="%"; >+my $dbh = C4::Context->dbh; >+my $query = q{ >+SELECT >+ ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="010"]/subfield[@code="a"]') as isbn1, >+ ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="010"]/subfield[@code="a"]') as isbn2, >+ ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="011"]/subfield[@code="a"]') as issn1, >+ ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="011"]/subfield[@code="a"]') as issn2, >+ ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="013"]/subfield[@code="a"]') as ismn1, >+ ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="013"]/subfield[@code="a"]') as ismn2, >+ ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="015"]/subfield[@code="a"]') as isrn1, >+ ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="015"]/subfield[@code="a"]') as isrn2, >+ ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="016"]/subfield[@code="a"]') as isrc1, >+ ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="016"]/subfield[@code="a"]') as isrc2, >+ ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="072"]/subfield[@code="a"]') as upc1, >+ ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="072"]/subfield[@code="a"]') as upc2, >+ ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="073"]/subfield[@code="a"]') as ean1, >+ ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="073"]/subfield[@code="a"]') as ean2 >+FROM >+ issues AS issues1 >+LEFT JOIN >+ issues AS issues2 ON issues1.borrowernumber=issues2.borrowernumber >+LEFT JOIN >+ items AS items1 ON issues1.itemnumber=items1.itemnumber >+LEFT JOIN >+ biblio_metadata AS biblio_metadata1 ON items1.biblionumber=biblio_metadata1.biblionumber >+LEFT JOIN >+ items AS items2 ON issues2.itemnumber=items2.itemnumber >+LEFT JOIN >+ biblio_metadata AS biblio_metadata2 ON items2.biblionumber=biblio_metadata2.biblionumber >+WHERE >+ issues1.issuedate LIKE '}.$date. q{%' AND biblio_metadata1.biblionumber>biblio_metadata2.biblionumber AND biblio_metadata1.format='marcxml' AND biblio_metadata2.format='marcxml' >+ORDER BY >+ issues1.borrowernumber,biblio_metadata1.biblionumber >+}; >+ >+my $sth = $dbh->prepare( $query ); >+$sth->execute; >+ >+my $row; >+my @reading_pairs; >+my $cter = 0; >+while ( $row = $sth->fetchrow_hashref ){ >+$row->{isbn1} = NormalizeISBN({ isbn => $row->{isbn1}, format => 'ISBN-13', strip_hyphens => 1 }); >+$row->{isbn2} = NormalizeISBN({ isbn => $row->{isbn2}, format => 'ISBN-13', strip_hyphens => 1 }); >+ my $currentpair; >+ foreach my $key1 ( qw ( isbn issn ismn isrn ean upc isrc ) ){ >+ foreach my $key2 ( qw ( isbn issn ismn isrn ean upc isrc ) ){ >+ if ( $row->{ $key1."1" } and $row->{ $key2."2" } ){ >+ $currentpair->{ idtype1 } = $key1; >+ $currentpair->{ documentid1 } = $row->{ $key1."1" }; >+ $currentpair->{ idtype2 } = $key2; >+ $currentpair->{ documentid2 } = $row->{ $key2."2" }; >+ push @reading_pairs, $currentpair; >+ >+ } >+ } >+ } >+} >+ >+my $securitytoken = C4::Context->preference('ManaToken'); >+my $MANA_IP; >+my $content; >+$MANA_IP=C4::Context->config("mana_config"); >+print $MANA_IP; >+$content->{ securitytoken } = $securitytoken; >+$content->{ reading_pairs } = \@reading_pairs; >+ >+my $url = "$MANA_IP/bulk/reading_pair.json"; >+my $request = HTTP::Request->new( POST => $url ); >+ >+my $json = to_json( $content, { utf8 => 1 } ); >+#print $json; >+ >+$request->content($json); >+my $result = Koha::SharedContent::manaRequest( $request ); >+print Data::Dumper::Dumper( $result ); >diff --git a/misc/cronjobs/mana_send_pairs_without_mana.pl b/misc/cronjobs/mana_send_pairs_without_mana.pl >new file mode 100644 >index 0000000000..c853832d65 >--- /dev/null >+++ b/misc/cronjobs/mana_send_pairs_without_mana.pl >@@ -0,0 +1,106 @@ >+use Modern::Perl; >+ >+use C4::Context; >+use Getopt::Long; >+use Koha; >+use C4::Koha; >+use Koha; >+ >+use JSON; >+use HTTP::Request; >+use LWP::UserAgent; >+ >+my $help = 0; >+my $man = 0; >+my $verbose = 0; >+my $date=DateTime->now()->strftime("%F"); >+ >+print $date."\n"; >+ >+ >+GetOptions( >+ 'help|?' => \$help, >+ 'man' => \$man, >+ 'v' => \$verbose, >+ 'date|d:s' => \$date >+); >+ >+ >+$date.="%"; >+my $dbh = C4::Context->dbh; >+my $query = q{ >+SELECT >+ ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="010"]/subfield[@code="a"]') as isbn1, >+ ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="010"]/subfield[@code="a"]') as isbn2, >+ ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="011"]/subfield[@code="a"]') as issn1, >+ ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="011"]/subfield[@code="a"]') as issn2, >+ ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="013"]/subfield[@code="a"]') as ismn1, >+ ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="013"]/subfield[@code="a"]') as ismn2, >+ ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="015"]/subfield[@code="a"]') as isrn1, >+ ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="015"]/subfield[@code="a"]') as isrn2, >+ ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="016"]/subfield[@code="a"]') as isrc1, >+ ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="016"]/subfield[@code="a"]') as isrc2, >+ ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="072"]/subfield[@code="a"]') as upc1, >+ ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="072"]/subfield[@code="a"]') as upc2, >+ ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="073"]/subfield[@code="a"]') as ean1, >+ ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="073"]/subfield[@code="a"]') as ean2 >+FROM >+ issues AS issues1 >+LEFT JOIN >+ issues AS issues2 ON issues1.borrowernumber=issues2.borrowernumber >+LEFT JOIN >+ items AS items1 ON issues1.itemnumber=items1.itemnumber >+LEFT JOIN >+ biblio_metadata AS biblio_metadata1 ON items1.biblionumber=biblio_metadata1.biblionumber >+LEFT JOIN >+ items AS items2 ON issues2.itemnumber=items2.itemnumber >+LEFT JOIN >+ biblio_metadata AS biblio_metadata2 ON items2.biblionumber=biblio_metadata2.biblionumber >+WHERE >+ issues1.issuedate LIKE '}.$date. q{' AND biblio_metadata1.biblionumber>biblio_metadata2.biblionumber AND biblio_metadata1.format='marcxml' AND biblio_metadata2.format='marcxml' >+ORDER BY >+ issues1.borrowernumber,biblio_metadata1.biblionumber >+}; >+ >+my $sth = $dbh->prepare( $query ); >+$sth->execute; >+ >+my $row; >+my @reading_pairs; >+my $cter = 0; >+while ( $row = $sth->fetchrow_hashref ){ >+$row->{isbn1} = NormalizeISBN({ isbn => $row->{isbn1}, format => 'ISBN-13', strip_hyphens => 1 }); >+$row->{isbn2} = NormalizeISBN({ isbn => $row->{isbn2}, format => 'ISBN-13', strip_hyphens => 1 }); >+ my $currentpair; >+ foreach my $key1 ( qw ( isbn issn ismn isrn ean upc isrc ) ){ >+ foreach my $key2 ( qw ( isbn issn ismn isrn ean upc isrc ) ){ >+ if ( $row->{ $key1."1" } and $row->{ $key2."2" } ){ >+ $currentpair->{ idtype1 } = $key1; >+ $currentpair->{ documentid1 } = $row->{ $key1."1" }; >+ $currentpair->{ idtype2 } = $key2; >+ $currentpair->{ documentid2 } = $row->{ $key2."2" }; >+ push @reading_pairs, $currentpair; >+ >+ } >+ } >+ } >+} >+ >+my $securitytoken = 'THIS_IS_A_TEST_ID'; >+my $MANA_IP; >+my $content; >+$MANA_IP='https://mana-kb.koha-community.org'; >+$content->{ securitytoken } = $securitytoken; >+$content->{ reading_pairs } = \@reading_pairs; >+ >+my $url = "$MANA_IP/bulk/reading_pair.json"; >+my $request = HTTP::Request->new( POST => $url ); >+ >+my $json = to_json( $content, { utf8 => 1 } ); >+#print $json; >+ >+$request->content($json); >+$request->content_type('aplication/json'); >+my $userAgent = LWP::UserAgent->new; >+my $response = $userAgent->request( $request ); >+print Data::Dumper::Dumper( $response )."\n"; >-- >2.17.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 18618
:
63496
|
63497
|
64531
|
64960
|
65066
|
65067
|
65068
|
65069
|
65070
|
130706
|
130707
|
130708
|
130709
|
130710
|
130711
|
130712
|
130713
|
130714
|
130715
|
130735
|
130736
|
130737
|
130738
|
130739
|
130740
|
130741
|
130742
|
130743
|
130744
|
132690
|
132691