Bugzilla – Attachment 130739 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: Rebase modification
Bug-18618-Rebase-modification.patch (text/plain), 12.28 KB, created by
Marion Durand
on 2022-02-17 13:27:36 UTC
(
hide
)
Description:
Bug 18618: Rebase modification
Filename:
MIME Type:
Creator:
Marion Durand
Created:
2022-02-17 13:27:36 UTC
Size:
12.28 KB
patch
obsolete
>From 51c14d4c36dc811286245cf956c0dc9e1a4881c9 Mon Sep 17 00:00:00 2001 >From: Marion Durand <marion.durand@biblibre.com> >Date: Wed, 15 Dec 2021 09:09:09 +0100 >Subject: [PATCH] Bug 18618: Rebase modification > >Remove mana_send_pairs_without_mana.pl > This script was here for testing purpose and is not usefull anymore >Fix name issues (some function have been renamed) >Fix a compilation issues (redeclared variable) >Remove an unused variable >Remove an extra % in an sql request >Fix display problem when getting info from mana > When getting info from mana the biblios array contain blessed references > but the template don't deal with that properly. > It work fine whe koha is getting info from it's interne database because > biblios array contain unblessed references. >--- > misc/cronjobs/mana_send_pairs.pl | 10 +- > misc/cronjobs/mana_send_pairs_without_mana.pl | 106 ------------------ > opac/svc/mana/getSuggestion | 30 ++--- > 3 files changed, 19 insertions(+), 127 deletions(-) > delete 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 >index e307ed0ff8..f54f7d0c9b 100644 >--- a/misc/cronjobs/mana_send_pairs.pl >+++ b/misc/cronjobs/mana_send_pairs.pl >@@ -28,8 +28,7 @@ GetOptions( > 'mana_ip|i:s' => \$MANA_IP > ); > >-my $securitytoken = C4::Context->preference('ManaToken'); >-$date.="%"; >+$securitytoken = C4::Context->preference('ManaToken'); > my $dbh = C4::Context->dbh; > my $query = q{ > SELECT >@@ -70,12 +69,11 @@ $sth->execute; > > my $row; > my @reading_pairs; >-my $cter = 0; > > #for each reading pair, processes the id pairs > 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 }); >+$row->{isbn1} = C4::Koha::NormalizeISBN({ isbn => $row->{isbn1}, format => 'ISBN-13', strip_hyphens => 1 }); >+$row->{isbn2} = C4::Koha::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 ) ){ >@@ -105,5 +103,5 @@ my $json = to_json( $content, { utf8 => 1 } ); > > #send to mana > $request->content($json); >-my $result = Koha::SharedContent::manaRequest( $request ); >+my $result = Koha::SharedContent::process_request( $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 >deleted file mode 100644 >index c853832d65..0000000000 >--- a/misc/cronjobs/mana_send_pairs_without_mana.pl >+++ /dev/null >@@ -1,106 +0,0 @@ >-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"; >diff --git a/opac/svc/mana/getSuggestion b/opac/svc/mana/getSuggestion >index 9c33985ac6..1ef8172197 100755 >--- a/opac/svc/mana/getSuggestion >+++ b/opac/svc/mana/getSuggestion >@@ -38,9 +38,8 @@ use DateTime::Format::MySQL; > use DateTime::Duration; > > use constant DURATION_BEFORE_REFRESH => DateTime::Duration->new( months => 3 ); >- > use C4::Output qw( output_with_http_headers ); >-my $input = new CGI; >+my $input = CGI->new; > binmode STDOUT, ":encoding(UTF-8)"; > > >@@ -70,6 +69,7 @@ eval { > $temp = $now - $timestamp; > }; > my @biblios; >+my @biblios_blessed; > if ( $local_suggestions and DateTime::Duration->compare( ($now - $timestamp), DURATION_BEFORE_REFRESH ) == -1 ){ > delete $local_suggestions->{timestamp}; > delete $local_suggestions->{biblionumber}; >@@ -86,7 +86,7 @@ else{ > my $notnormalizeddocumentid; > if ( $biblioitem->isbn ){ > $idtype= "isbn"; >- $documentid= NormalizeISBN({ isbn => $biblioitem->isbn, format => 'ISBN-13', strip_hyphens => 1 }); >+ $documentid= C4::Koha::NormalizeISBN({ isbn => $biblioitem->isbn, format => 'ISBN-13', strip_hyphens => 1 }); > } > elsif ( $biblioitem->issn ){ > $idtype= "issn"; >@@ -110,7 +110,7 @@ else{ > my $url = "$mana_ip/getsuggestion/$notnormalizeddocumentid/$idtype?offset=$offset&length=$length"; > my $request = HTTP::Request->new( GET => $url ); > $request->content_type('aplication/json'); >- my $response = Koha::SharedContent::manaRequest( $request ); >+ my $response = Koha::SharedContent::process_request( $request ); > > #error handling > my $resources = $response->{data}; >@@ -139,22 +139,22 @@ else{ > foreach my $resource ( @{ $resources } ){ > # Â isbn processsing > if ( $resource->{idtype} eq "isbn" ){ >- $documentid= NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-10', strip_hyphens => 1 }); >+ $documentid= C4::Koha::NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-10', strip_hyphens => 1 }); > $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid; > > #if we don't have such a biblioitem, we try to format else the isbn > unless ( scalar @{ $ownedbiblioitem->unblessed() } ){ >- $documentid = NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-13', strip_hyphens => 1 }); >+ $documentid = C4::Koha::NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-13', strip_hyphens => 1 }); > $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid; > } > > unless ( scalar @{ $ownedbiblioitem->unblessed() } ){ >- $documentid = NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-10', strip_hyphens => 0 }); >+ $documentid = C4::Koha::NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-10', strip_hyphens => 0 }); > $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid; > } > > unless ( scalar @{ $ownedbiblioitem->unblessed() } ){ >- $documentid = NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-13', strip_hyphens => 0 }); >+ $documentid = C4::Koha::NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-13', strip_hyphens => 0 }); > $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid; > } > >@@ -165,11 +165,12 @@ else{ > } > if (scalar @{ $ownedbiblioitem->unblessed() } ){ > my $ownedbiblio = Koha::Biblios->find( @{ $ownedbiblioitem->unblessed() }[0]->{biblionumber} ); >- push @biblios, $ownedbiblio; >+ push @biblios_blessed, $ownedbiblio; >+ push @biblios, $ownedbiblio->unblessed(); > } > } > #the number of requested resource is inversely proportionnal to the found_items/returned_items ratio, +1 is here just to avoid 0 >- my $newlength = int( ( 10*( $length + $offset ) - $length ) / (scalar @biblios + 1 )); >+ my $newlength = int( ( 10*( $length + $offset ) - $length ) / (scalar @biblios_blessed + 1 )); > if ( $newlength > 500 ){ > $newlength = 500; > } >@@ -177,16 +178,16 @@ else{ > $length = $newlength; > > >- } while( (scalar @biblios < 10 ) and $mananotover ); >+ } while( (scalar @biblios_blessed < 10 ) and $mananotover ); > > #preparing new suggestion > my $newSuggestion; >- my $cter = scalar @biblios; >+ my $cter = scalar @biblios_blessed; > $cter = 10 unless ($cter < 10); > $newSuggestion->{ biblionumber } = $biblionumber; > while ( $cter > 0 ){ >- if ( $biblios[ $cter-1 ] and $biblios[ $cter-1 ]->biblionumber){ >- $newSuggestion->{ "biblionumber".$cter }=$biblios[ $cter-1 ]->biblionumber; >+ if ( $biblios_blessed[ $cter-1 ] and $biblios_blessed[ $cter-1 ]->biblionumber){ >+ $newSuggestion->{ "biblionumber".$cter }=$biblios_blessed[ $cter-1 ]->biblionumber; > } > $cter--; > } >@@ -205,7 +206,6 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > debug => 1, > } > ); >- > $template->param( JacketImage => 1); > $template->param( suggestions => \@biblios ); > >-- >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