Bug 31682: Silence automatic linker warn
[koha.git] / 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 qw( to_json );
23 use C4::Auth qw( check_cookie_auth );
24 use C4::Biblio qw( BiblioAutoLink TransformHtmlToMarc );
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 ) =
32   C4::Auth::check_cookie_auth( $input->cookie('CGISESSID'), {
33     editauthorities => 1,
34     editcatalogue => 'edit_catalogue'
35   });
36 if ( $auth_status ne "ok" ) {
37     print to_json( { status => 'UNAUTHORIZED' } );
38     exit 0;
39 }
40
41 # Link the biblio headings to authorities and return a json containing the status of all the links.
42 # Example : {"status":"OK","links":[{"authid":"123","status":"LINK_CHANGED","tag":"650"}]}
43 #
44 # tag = the tag number of the field
45 # authid = the value of the $9 subfield for this tag
46 # status = The status of the link (LOCAL_FOUND, NONE_FOUND, MULTIPLE_MATCH, UNCHANGED, CREATED)
47
48 my $json;
49
50 my $record = TransformHtmlToMarc($input,1);
51
52 my ( $headings_changed, $results ) = BiblioAutoLink (
53     $record,
54     scalar $input->param('frameworkcode'),
55     1
56 );
57
58 $json->{status} = 'OK';
59 $json->{links} = $results->{details} || '';
60
61 print to_json($json);