Bug 35579: Cache authorised value lookup by MARC field
[koha.git] / catalogue / showelastic.pl
1 #!/usr/bin/perl
2
3 # Koha library project  www.koha-community.org
4
5 # Copyright 2020 Koha Development Team
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21
22
23 use Modern::Perl;
24
25 # standard or CPAN modules used
26 use CGI qw(:standard -utf8);
27 use DBI;
28 use Encode;
29 use JSON;
30 use Try::Tiny;
31
32 # Koha modules used
33 use C4::Context;
34 use C4::Output qw( output_html_with_http_headers );
35 use C4::Auth qw(get_template_and_user);
36 use C4::Biblio;
37 use C4::ImportBatch;
38 use C4::XSLT ;
39 use Koha::SearchEngine::Elasticsearch;
40 use LWP::Simple qw/get/;
41
42 my $input= CGI->new;
43 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
44   {
45     template_name   => "catalogue/showelastic.tt",
46     query           => $input,
47     type            => "intranet",
48     flagsrequired   => { catalogue => 1  },
49     debug           => 1,
50   }
51 );
52
53 my $biblionumber = $input->param('id');
54
55 my $es = Koha::SearchEngine::Elasticsearch->new({index=>'biblios'});
56
57 my $es_record;
58 my @es_fields;
59
60 try {
61     $es_record = $es->get_elasticsearch()->get({
62         index => $es->index_name,
63         type  => 'data',
64         id    => $biblionumber,
65     });
66 }
67 catch{
68     warn $_;
69     print $input->redirect("/cgi-bin/koha/errors/404.pl");
70 };
71
72 for my $field (sort keys %{$es_record} ){
73     push @es_fields, { $field, $es_record->{$field} };
74 };
75 $template->param( esrecord => to_json( \@es_fields ) );
76 output_html_with_http_headers $input, $cookie, $template->output;