a04ccfb8c97310aa5de738bab67fdc8c147bf3a9
[srvgit] / svc / cataloguing / automatic_linker.pl
1 #!/usr/bin/perl
2
3 # Bouzid Fergani, 2020   - inLibro
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21 use CGI;
22 use JSON;
23 use C4::Auth qw(check_cookie_auth);
24 use C4::Biblio;
25 use C4::Context;
26
27 my $input = CGI->new;
28 print $input->header('application/json');
29
30 # Check the user's permissions
31 my ( $auth_status, $auth_sessid ) =
32   C4::Auth::check_cookie_auth( $input->cookie('CGISESSID'), { editauthorities => 1, editcatalogue => 1 } );
33 if ( $auth_status ne "ok" ) {
34     print to_json( { status => 'UNAUTHORIZED' } );
35     exit 0;
36 }
37
38 # Link the biblio headings to authorities and return a json containing the status of all the links.
39 # Example : {"status":"OK","links":[{"authid":"123","status":"LINK_CHANGED","tag":"650"}]}
40 #
41 # tag = the tag number of the field
42 # authid = the value of the $9 subfield for this tag
43 # status = The status of the link (LOCAL_FOUND, NONE_FOUND, MULTIPLE_MATCH, UNCHANGED, CREATED)
44
45 my $json;
46
47 my $record = TransformHtmlToMarc($input,1);
48
49 my ( $headings_changed, $results ) = BiblioAutoLink (
50     $record,
51     $input->param('frameworkcode'),
52     1
53 );
54
55 $json->{status} = 'OK';
56 $json->{links} = $results->{details} || '';
57
58 print to_json($json);