Bugzilla – Attachment 65069 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: Add a pagination for suggestions
Bug-18618-Add-a-pagination-for-suggestions.patch (text/plain), 11.71 KB, created by
Brendan Gallagher
on 2017-07-14 19:57:34 UTC
(
hide
)
Description:
Bug 18618: Add a pagination for suggestions
Filename:
MIME Type:
Creator:
Brendan Gallagher
Created:
2017-07-14 19:57:34 UTC
Size:
11.71 KB
patch
obsolete
>From 0396181144f00ab49291e8cfa1483f7db0a03ecf Mon Sep 17 00:00:00 2001 >From: Baptiste Wojtkowski <baptiste.wojtkowski@biblibre.com> >Date: Thu, 22 Jun 2017 07:49:42 +0000 >Subject: [PATCH] Bug 18618: Add a pagination for suggestions > >*** Suggestions are now sent from Mana as follows > >- Koha requests the first 20 suggestions >- It processes them and estimates how much it will need to get all suggestions >- It requests Mana the number of suggestions needed >- It repeats the 3 first steps until > (1) Mana doesn't have suggestions anymore > (2) It got 10 suggestions to display > >*** Koha interface is a bit more verbose while searching (just a bit). > >Signed-off-by: Brendan A Gallagher <brendan@bywatersolutions.com> >--- > .../opac-tmpl/bootstrap/en/modules/opac-detail.tt | 2 +- > misc/cronjobs/mana_send_pairs.pl | 18 +-- > opac/svc/mana/getSuggestion | 139 +++++++++++++-------- > 3 files changed, 98 insertions(+), 61 deletions(-) > >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt >index 4c51b5c..a663ca3 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt >@@ -1938,9 +1938,9 @@ > > [% IF Koha.Preference('Mana') %] > <script> >- $("#reading_suggestions").html(""); > $(document).ready( function(){ > $( "#tab_suggestions" ).one( "click", function(){ >+ $("#reading_suggestions").html("<h1> Asking Mana Servers.. Please wait..</h1>"); > $.ajax({ > type: "POST", > url: "/cgi-bin/koha/svc/mana/getSuggestion", >diff --git a/misc/cronjobs/mana_send_pairs.pl b/misc/cronjobs/mana_send_pairs.pl >index 50ea86b..880d029 100644 >--- a/misc/cronjobs/mana_send_pairs.pl >+++ b/misc/cronjobs/mana_send_pairs.pl >@@ -1,3 +1,4 @@ >+#/!usr/bin/perl > use Modern::Perl; > > use C4::Context; >@@ -15,17 +16,19 @@ my $man = 0; > my $verbose = 0; > my $date=DateTime->now()->strftime("%F"); > >-print $date; >- >+my $securitytoken; >+my $MANA_IP; > > GetOptions( > 'help|?' => \$help, > 'man' => \$man, > 'v' => \$verbose, > 'date|d:s' => \$date >+ 'security_token|s:s' => \$securitytoken, >+ 'mana_ip|i:s' => \$MANA_IP > ); > >- >+my $securitytoken = C4::Context->preference('ManaToken'); > $date.="%"; > my $dbh = C4::Context->dbh; > my $query = q{ >@@ -68,6 +71,8 @@ $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 }); >@@ -80,17 +85,15 @@ $row->{isbn2} = NormalizeISBN({ isbn => $row->{isbn2}, format => 'ISBN-13', stri > $currentpair->{ idtype2 } = $key2; > $currentpair->{ documentid2 } = $row->{ $key2."2" }; > push @reading_pairs, $currentpair; >- > } > } > } > } > >-my $securitytoken = C4::Context->preference('ManaToken'); >-my $MANA_IP; > my $content; >+ >+#informations for mana > $MANA_IP=C4::Context->config("mana_config"); >-print $MANA_IP; > $content->{ securitytoken } = $securitytoken; > $content->{ reading_pairs } = \@reading_pairs; > >@@ -100,6 +103,7 @@ my $request = HTTP::Request->new( POST => $url ); > my $json = to_json( $content, { utf8 => 1 } ); > #print $json; > >+#send to mana > $request->content($json); > my $result = Koha::SharedContent::manaRequest( $request ); > print Data::Dumper::Dumper( $result ); >diff --git a/opac/svc/mana/getSuggestion b/opac/svc/mana/getSuggestion >index 3760451..682b867 100755 >--- a/opac/svc/mana/getSuggestion >+++ b/opac/svc/mana/getSuggestion >@@ -42,7 +42,19 @@ use constant DURATION_BEFORE_REFRESH => DateTime::Duration->new( months => 3 ); > use C4::Output qw( output_with_http_headers ); > my $input = new CGI; > binmode STDOUT, ":encoding(UTF-8)"; >+ >+ >+ >+ > my $biblionumber = $input->param( "biblionumber" ); >+ >+#case we come with the script import_suggestions.pl >+my $temp_biblionumber; >+eval { $temp_biblionumber = from_json( $input->param( "POSTDATA" ) )->{biblionumber}; }; >+if ( $temp_biblionumber ){ >+ $biblionumber = $temp_biblionumber; >+} >+ > my $biblioitem = Koha::Biblioitems->find( $biblionumber ); > > my $local_suggestions; >@@ -65,10 +77,12 @@ if ( $local_suggestions and DateTime::Duration->compare( ($now - $timestamp), DU > push @biblios, Koha::Biblios->find( $local_suggestions->{ $key } ); > } > } >+ > else{ > # get all informations to ask mana > my $idtype; > my $documentid; >+ my $notnormalizeddocumentid; > if ( $biblioitem->isbn ){ > $idtype= "isbn"; > $documentid= NormalizeISBN({ isbn => $biblioitem->isbn, format => 'ISBN-13', strip_hyphens => 1 }); >@@ -84,80 +98,101 @@ else{ > else{ > die "error: no propper identifier"; > } >+ $notnormalizeddocumentid = $documentid; >+ my $offset = 1; >+ my $length = 10; >+ my $mananotover; >+ >+ do{ >+ #request mana >+ my $mana_ip = C4::Context->config('mana_config'); >+ 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 ); >+ >+ #error handling >+ my $resources = $response->{data}; >+ unless ( $resources ){ >+ my $msg; >+ $msg = $response->{msg}; >+ if ( $msg ){ >+ die $msg; >+ } >+ else{ >+ die "Unknown error"; >+ } >+ } > >- #request mana >- my $mana_ip = C4::Context->config('mana_config'); >- my $url = "$mana_ip/getsuggestion/$documentid/$idtype"; >- my $request = HTTP::Request->new( GET => $url ); >- $request->content_type('aplication/json'); >- my $response = Koha::SharedContent::manaRequest( $request ); >- >- #error handling >- my $resources = $response->{data}; >- unless ( $resources ){ >- my $msg; >- $msg = $response->{msg}; >- if ( $msg ){ >- die $msg; >+ if ( scalar @{ $resources } < $length ){ >+ $mananotover = 0; > } > else{ >- die "Unknown error"; >+ $mananotover = 1; > } >- } >- #create the list of owned suggested resources >- my $ownedbiblioitem; >- my $ownedbiblio; >- foreach my $resource ( @{ $resources } ){ > > >- # Â isbn processsing >- if ( $resource->{idtype} eq "isbn" ){ >- $documentid= NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-10', strip_hyphens => 1 }); >- $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $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 }); >- $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}); >- } >+ #create the list of owned suggested resources >+ my $ownedbiblioitem; >+ foreach my $resource ( @{ $resources } ){ >+ # Â isbn processsing >+ if ( $resource->{idtype} eq "isbn" ){ >+ $documentid= NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-10', 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 }); >- $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $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 }); >+ $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid; >+ } > >- unless ( scalar @{ $ownedbiblioitem->unblessed() } ){ >- $documentid = NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-13', strip_hyphens => 0 }); >- $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}); >- } >+ unless ( scalar @{ $ownedbiblioitem->unblessed() } ){ >+ $documentid = 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 }); >+ $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid; >+ } >+ >+ } >+ #others ids do not need any processing >+ else{ >+ $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $resource->{documentid} }); >+ } >+ if (scalar @{ $ownedbiblioitem->unblessed() } ){ >+ my $ownedbiblio = Koha::Biblios->find( @{ $ownedbiblioitem->unblessed() }[0]->{biblionumber} ); >+ push @biblios, $ownedbiblio; >+ } > } >- #others ids do not need any processing >- else{ >- $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}); >- } >- if (scalar @{ $ownedbiblioitem->unblessed() } ){ >- $ownedbiblio = Koha::Biblios->find( @{ $ownedbiblioitem->unblessed() }[0]->{biblionumber} ); >- push @biblios, $ownedbiblio; >- } >- } >+ #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 )); >+ if ( $newlength > 500 ){ >+ $newlength = 500; >+ } >+ $offset += $length; >+ $length = $newlength; >+ >+ >+ } while( (scalar @biblios < 10 ) and $mananotover ); > > #preparing new suggestion > my $newSuggestion; > my $cter = scalar @biblios; > $cter = 10 unless ($cter < 10); > $newSuggestion->{ biblionumber } = $biblionumber; >- if ( scalar @biblios < 11 ){ >- while ( $cter > 1 ){ >- $cter--; >- $newSuggestion->{ "biblionumber".$cter }=$biblios[ $cter ]->biblionumber; >+ while ( $cter > 0 ){ >+ if ( $biblios[ $cter-1 ] and $biblios[ $cter-1 ]->biblionumber){ >+ $newSuggestion->{ "biblionumber".$cter }=$biblios[ $cter-1 ]->biblionumber; > } >+ $cter--; > } > if ( $local_suggestions ){ > Koha::Reading_suggestions->find( $biblionumber )->delete(); > } > Koha::Reading_suggestion->new( $newSuggestion )->store; >- > } > > my ( $template, $loggedinuser, $cookie ) = get_template_and_user( >@@ -170,9 +205,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > } > ); > >- > $template->param( JacketImage => 1); > $template->param( suggestions => \@biblios ); > >- > output_with_http_headers $input, $cookie, $template->output, 'json'; >-- >2.1.4
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