View | Details | Raw Unified | Return to bug 18618
Collapse All | Expand All

(-)a/misc/cronjobs/mana_send_pairs.pl (-6 / +4 lines)
Lines 28-35 GetOptions( Link Here
28
            'mana_ip|i:s'    => \$MANA_IP
28
            'mana_ip|i:s'    => \$MANA_IP
29
);
29
);
30
30
31
my $securitytoken = C4::Context->preference('ManaToken');
31
$securitytoken = C4::Context->preference('ManaToken');
32
$date.="%";
33
my $dbh = C4::Context->dbh;
32
my $dbh = C4::Context->dbh;
34
my $query = q{
33
my $query = q{
35
SELECT
34
SELECT
Lines 70-81 $sth->execute; Link Here
70
69
71
my $row;
70
my $row;
72
my @reading_pairs;
71
my @reading_pairs;
73
my $cter = 0;
74
72
75
#for each reading pair, processes the id pairs
73
#for each reading pair, processes the id pairs
76
while ( $row = $sth->fetchrow_hashref ){
74
while ( $row = $sth->fetchrow_hashref ){
77
$row->{isbn1} = NormalizeISBN({ isbn => $row->{isbn1}, format => 'ISBN-13', strip_hyphens => 1  });
75
$row->{isbn1} = C4::Koha::NormalizeISBN({ isbn => $row->{isbn1}, format => 'ISBN-13', strip_hyphens => 1  });
78
$row->{isbn2} = NormalizeISBN({ isbn => $row->{isbn2}, format => 'ISBN-13', strip_hyphens => 1 });
76
$row->{isbn2} = C4::Koha::NormalizeISBN({ isbn => $row->{isbn2}, format => 'ISBN-13', strip_hyphens => 1 });
79
    my $currentpair;
77
    my $currentpair;
80
    foreach my $key1 ( qw ( isbn issn ismn isrn ean upc isrc ) ){
78
    foreach my $key1 ( qw ( isbn issn ismn isrn ean upc isrc ) ){
81
        foreach my $key2 ( qw ( isbn issn ismn isrn ean upc isrc ) ){
79
        foreach my $key2 ( qw ( isbn issn ismn isrn ean upc isrc ) ){
Lines 105-109 my $json = to_json( $content, { utf8 => 1 } ); Link Here
105
103
106
#send to mana
104
#send to mana
107
$request->content($json);
105
$request->content($json);
108
my $result = Koha::SharedContent::manaRequest( $request );
106
my $result = Koha::SharedContent::process_request( $request );
109
print Data::Dumper::Dumper( $result );
107
print Data::Dumper::Dumper( $result );
(-)a/misc/cronjobs/mana_send_pairs_without_mana.pl (-106 lines)
Lines 1-106 Link Here
1
use Modern::Perl;
2
3
use C4::Context;
4
use Getopt::Long;
5
use Koha;
6
use C4::Koha;
7
use Koha;
8
9
use JSON;
10
use HTTP::Request;
11
use LWP::UserAgent;
12
13
my $help = 0;
14
my $man = 0;
15
my $verbose = 0;
16
my $date=DateTime->now()->strftime("%F");
17
18
print $date."\n";
19
20
21
GetOptions(
22
            'help|?'         => \$help,
23
            'man'            => \$man,
24
            'v'              => \$verbose,
25
            'date|d:s'       => \$date
26
);
27
28
29
$date.="%";
30
my $dbh = C4::Context->dbh;
31
my $query = q{
32
SELECT
33
    ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="010"]/subfield[@code="a"]') as isbn1,
34
    ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="010"]/subfield[@code="a"]') as isbn2,
35
    ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="011"]/subfield[@code="a"]') as issn1,
36
    ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="011"]/subfield[@code="a"]') as issn2,
37
    ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="013"]/subfield[@code="a"]') as ismn1,
38
    ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="013"]/subfield[@code="a"]') as ismn2,
39
    ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="015"]/subfield[@code="a"]') as isrn1,
40
    ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="015"]/subfield[@code="a"]') as isrn2,
41
    ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="016"]/subfield[@code="a"]') as isrc1,
42
    ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="016"]/subfield[@code="a"]') as isrc2,
43
    ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="072"]/subfield[@code="a"]') as upc1,
44
    ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="072"]/subfield[@code="a"]') as upc2,
45
    ExtractValue(biblio_metadata1.metadata, '//datafield[@tag="073"]/subfield[@code="a"]') as ean1,
46
    ExtractValue(biblio_metadata2.metadata, '//datafield[@tag="073"]/subfield[@code="a"]') as ean2
47
FROM
48
    issues AS issues1
49
LEFT JOIN
50
    issues AS issues2 ON issues1.borrowernumber=issues2.borrowernumber
51
LEFT JOIN
52
    items AS items1 ON issues1.itemnumber=items1.itemnumber
53
LEFT JOIN
54
    biblio_metadata AS biblio_metadata1 ON items1.biblionumber=biblio_metadata1.biblionumber
55
LEFT JOIN
56
    items AS items2 ON issues2.itemnumber=items2.itemnumber
57
LEFT JOIN
58
    biblio_metadata AS biblio_metadata2 ON items2.biblionumber=biblio_metadata2.biblionumber
59
WHERE
60
    issues1.issuedate LIKE '}.$date. q{' AND biblio_metadata1.biblionumber>biblio_metadata2.biblionumber AND biblio_metadata1.format='marcxml' AND biblio_metadata2.format='marcxml'
61
ORDER BY
62
    issues1.borrowernumber,biblio_metadata1.biblionumber
63
};
64
65
my $sth = $dbh->prepare( $query );
66
$sth->execute;
67
68
my $row;
69
my @reading_pairs;
70
my $cter = 0;
71
while ( $row = $sth->fetchrow_hashref ){
72
$row->{isbn1} = NormalizeISBN({ isbn => $row->{isbn1}, format => 'ISBN-13', strip_hyphens => 1  });
73
$row->{isbn2} = NormalizeISBN({ isbn => $row->{isbn2}, format => 'ISBN-13', strip_hyphens => 1 });
74
    my $currentpair;
75
    foreach my $key1 ( qw ( isbn issn ismn isrn ean upc isrc ) ){
76
        foreach my $key2 ( qw ( isbn issn ismn isrn ean upc isrc ) ){
77
            if ( $row->{ $key1."1" } and $row->{ $key2."2" } ){
78
                 $currentpair->{ idtype1 } = $key1;
79
                 $currentpair->{ documentid1 } = $row->{ $key1."1" };
80
                 $currentpair->{ idtype2 } = $key2;
81
                 $currentpair->{ documentid2 } = $row->{ $key2."2" };
82
                 push @reading_pairs, $currentpair;
83
84
            }
85
        }
86
    }
87
}
88
89
my $securitytoken = 'THIS_IS_A_TEST_ID';
90
my $MANA_IP;
91
my $content;
92
$MANA_IP='https://mana-kb.koha-community.org';
93
$content->{ securitytoken } = $securitytoken;
94
$content->{ reading_pairs } = \@reading_pairs;
95
96
my $url = "$MANA_IP/bulk/reading_pair.json";
97
my $request = HTTP::Request->new( POST => $url );
98
99
my $json = to_json( $content, { utf8 => 1 } );
100
#print $json;
101
102
$request->content($json);
103
$request->content_type('aplication/json');
104
my $userAgent = LWP::UserAgent->new;
105
my $response  = $userAgent->request( $request );
106
print Data::Dumper::Dumper( $response )."\n";
(-)a/opac/svc/mana/getSuggestion (-16 / +15 lines)
Lines 38-46 use DateTime::Format::MySQL; Link Here
38
use DateTime::Duration;
38
use DateTime::Duration;
39
39
40
use constant DURATION_BEFORE_REFRESH => DateTime::Duration->new( months => 3 );
40
use constant DURATION_BEFORE_REFRESH => DateTime::Duration->new( months => 3 );
41
42
use C4::Output qw( output_with_http_headers );
41
use C4::Output qw( output_with_http_headers );
43
my $input = new CGI;
42
my $input = CGI->new;
44
binmode STDOUT, ":encoding(UTF-8)";
43
binmode STDOUT, ":encoding(UTF-8)";
45
44
46
45
Lines 70-75 eval { Link Here
70
    $temp = $now - $timestamp;
69
    $temp = $now - $timestamp;
71
};
70
};
72
my @biblios;
71
my @biblios;
72
my @biblios_blessed;
73
if ( $local_suggestions and DateTime::Duration->compare( ($now - $timestamp), DURATION_BEFORE_REFRESH ) == -1 ){
73
if ( $local_suggestions and DateTime::Duration->compare( ($now - $timestamp), DURATION_BEFORE_REFRESH ) == -1 ){
74
        delete $local_suggestions->{timestamp};
74
        delete $local_suggestions->{timestamp};
75
        delete $local_suggestions->{biblionumber};
75
        delete $local_suggestions->{biblionumber};
Lines 86-92 else{ Link Here
86
    my $notnormalizeddocumentid;
86
    my $notnormalizeddocumentid;
87
    if ( $biblioitem->isbn ){
87
    if ( $biblioitem->isbn ){
88
        $idtype= "isbn";
88
        $idtype= "isbn";
89
        $documentid= NormalizeISBN({ isbn => $biblioitem->isbn, format => 'ISBN-13', strip_hyphens => 1 });
89
        $documentid= C4::Koha::NormalizeISBN({ isbn => $biblioitem->isbn, format => 'ISBN-13', strip_hyphens => 1 });
90
    }
90
    }
91
    elsif ( $biblioitem->issn ){
91
    elsif ( $biblioitem->issn ){
92
        $idtype= "issn";
92
        $idtype= "issn";
Lines 110-116 else{ Link Here
110
        my $url = "$mana_ip/getsuggestion/$notnormalizeddocumentid/$idtype?offset=$offset&length=$length";
110
        my $url = "$mana_ip/getsuggestion/$notnormalizeddocumentid/$idtype?offset=$offset&length=$length";
111
        my $request = HTTP::Request->new( GET => $url );
111
        my $request = HTTP::Request->new( GET => $url );
112
        $request->content_type('aplication/json');
112
        $request->content_type('aplication/json');
113
        my $response = Koha::SharedContent::manaRequest( $request );
113
        my $response = Koha::SharedContent::process_request( $request );
114
114
115
        #error handling
115
        #error handling
116
        my $resources = $response->{data};
116
        my $resources = $response->{data};
Lines 139-160 else{ Link Here
139
        foreach my $resource ( @{ $resources } ){
139
        foreach my $resource ( @{ $resources } ){
140
        #   isbn processsing
140
        #   isbn processsing
141
            if ( $resource->{idtype} eq "isbn" ){
141
            if ( $resource->{idtype} eq "isbn" ){
142
                $documentid= NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-10', strip_hyphens => 1 });
142
                $documentid= C4::Koha::NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-10', strip_hyphens => 1 });
143
                $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid;
143
                $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid;
144
144
145
            #if we don't have such a biblioitem, we try to format else the isbn
145
            #if we don't have such a biblioitem, we try to format else the isbn
146
                unless ( scalar @{ $ownedbiblioitem->unblessed() } ){
146
                unless ( scalar @{ $ownedbiblioitem->unblessed() } ){
147
                    $documentid = NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-13', strip_hyphens => 1 });
147
                    $documentid = C4::Koha::NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-13', strip_hyphens => 1 });
148
                    $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid;
148
                    $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid;
149
                }
149
                }
150
150
151
                unless ( scalar @{ $ownedbiblioitem->unblessed() } ){
151
                unless ( scalar @{ $ownedbiblioitem->unblessed() } ){
152
                    $documentid = NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-10', strip_hyphens => 0 });
152
                    $documentid = C4::Koha::NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-10', strip_hyphens => 0 });
153
                    $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid;
153
                    $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid;
154
                }
154
                }
155
155
156
                unless ( scalar @{ $ownedbiblioitem->unblessed() } ){
156
                unless ( scalar @{ $ownedbiblioitem->unblessed() } ){
157
                    $documentid = NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-13', strip_hyphens => 0 });
157
                    $documentid = C4::Koha::NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-13', strip_hyphens => 0 });
158
                    $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid;
158
                    $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid;
159
                }
159
                }
160
160
Lines 165-175 else{ Link Here
165
            }
165
            }
166
            if (scalar @{ $ownedbiblioitem->unblessed() } ){
166
            if (scalar @{ $ownedbiblioitem->unblessed() } ){
167
                my $ownedbiblio = Koha::Biblios->find(  @{ $ownedbiblioitem->unblessed() }[0]->{biblionumber} );
167
                my $ownedbiblio = Koha::Biblios->find(  @{ $ownedbiblioitem->unblessed() }[0]->{biblionumber} );
168
                push @biblios, $ownedbiblio;
168
                push @biblios_blessed, $ownedbiblio;
169
                push @biblios, $ownedbiblio->unblessed();
169
            }
170
            }
170
        }
171
        }
171
            #the number of requested resource is inversely proportionnal to the found_items/returned_items ratio, +1 is here just to avoid 0
172
            #the number of requested resource is inversely proportionnal to the found_items/returned_items ratio, +1 is here just to avoid 0
172
            my $newlength = int( ( 10*( $length + $offset ) - $length ) / (scalar @biblios + 1 ));
173
            my $newlength = int( ( 10*( $length + $offset ) - $length ) / (scalar @biblios_blessed + 1 ));
173
            if ( $newlength > 500 ){
174
            if ( $newlength > 500 ){
174
                $newlength = 500;
175
                $newlength = 500;
175
            }
176
            }
Lines 177-192 else{ Link Here
177
            $length = $newlength;
178
            $length = $newlength;
178
179
179
180
180
    } while( (scalar @biblios < 10 ) and $mananotover );
181
    } while( (scalar @biblios_blessed < 10 ) and $mananotover );
181
182
182
    #preparing new suggestion
183
    #preparing new suggestion
183
    my $newSuggestion;
184
    my $newSuggestion;
184
    my $cter = scalar @biblios;
185
    my $cter = scalar @biblios_blessed;
185
    $cter = 10 unless ($cter < 10);
186
    $cter = 10 unless ($cter < 10);
186
    $newSuggestion->{ biblionumber } = $biblionumber;
187
    $newSuggestion->{ biblionumber } = $biblionumber;
187
    while ( $cter > 0 ){
188
    while ( $cter > 0 ){
188
        if ( $biblios[ $cter-1 ] and $biblios[ $cter-1 ]->biblionumber){
189
        if ( $biblios_blessed[ $cter-1 ] and $biblios_blessed[ $cter-1 ]->biblionumber){
189
            $newSuggestion->{ "biblionumber".$cter }=$biblios[ $cter-1 ]->biblionumber;
190
            $newSuggestion->{ "biblionumber".$cter }=$biblios_blessed[ $cter-1 ]->biblionumber;
190
        }
191
        }
191
        $cter--;
192
        $cter--;
192
    }
193
    }
Lines 205-211 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
205
        debug           => 1,
206
        debug           => 1,
206
    }
207
    }
207
);
208
);
208
209
$template->param( JacketImage => 1);
209
$template->param( JacketImage => 1);
210
$template->param( suggestions => \@biblios );
210
$template->param( suggestions => \@biblios );
211
211
212
- 

Return to bug 18618