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

(-)a/misc/cronjobs/mana_send_pairs.pl (+105 lines)
Line 0 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 Koha::SharedContent;
12
13
my $help = 0;
14
my $man = 0;
15
my $verbose = 0;
16
my $date=DateTime->now()->strftime("%F");
17
18
print $date;
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 = C4::Context->preference('ManaToken');
90
my $MANA_IP;
91
my $content;
92
$MANA_IP=C4::Context->config("mana_config");
93
print $MANA_IP;
94
$content->{ securitytoken } = $securitytoken;
95
$content->{ reading_pairs } = \@reading_pairs;
96
97
my $url = "$MANA_IP/bulk/reading_pair.json";
98
my $request = HTTP::Request->new( POST => $url );
99
100
my $json = to_json( $content, { utf8 => 1 } );
101
#print $json;
102
103
$request->content($json);
104
my $result = Koha::SharedContent::manaRequest( $request );
105
print Data::Dumper::Dumper( $result );
(-)a/misc/cronjobs/mana_send_pairs_without_mana.pl (-1 / +106 lines)
Line 0 Link Here
0
- 
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";

Return to bug 18618