3 # Copyright 2012 BibLibre SARL
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 use Koha::SearchEngine;
28 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
30 template_name => 'admin/searchengine/solr/indexes.tt',
33 # authnotrequired => 0,
34 # flagsrequired => { reserveforothers => "place_holds" }, #TODO
38 my $ressource_type = $input->param('ressource_type') || 'biblio';
39 my $se = Koha::SearchEngine->new;
40 my $se_config = $se->config;
43 if ( $input->param('op') and $input->param('op') eq 'edit' ) {
44 my @code = $input->param('code');
45 my @label = $input->param('label');
46 my @type = $input->param('type');
47 my @sortable = $input->param('sortable');
48 my @facetable = $input->param('facetable');
49 my @mandatory = $input->param('mandatory');
50 my @ressource_type = $input->param('ressource_type');
51 my @mappings = $input->param('mappings');
54 for ( 0 .. @code-1 ) {
55 my $icode = $code[$_];
56 my @current_mappings = split /\r\n/, $mappings[$_];
57 if ( not @current_mappings ) {
58 @current_mappings = split /\n/, $mappings[$_];
60 if ( not @current_mappings ) {
61 push @errors, { type => 'no_mapping', value => $icode};
68 sortable => scalar(grep(/^$icode$/, @sortable)),
69 facetable => scalar(grep(/^$icode$/, @facetable)),
70 mandatory => $mandatory[$_] eq '1' ? '1' : '0',
71 ressource_type => $ressource_type[$_],
72 mappings => \@current_mappings,
74 for my $m ( @current_mappings ) {
75 push @errors, {type => 'malformed_mapping', value => $m}
76 if not $m =~ /^\d(\d|\*|\.){2}\$.$/;
79 $indexes = \@indexes if @errors;
80 $template->param( errors => \@errors );
82 $se_config->indexes(\@indexes) if not @errors;
85 my $ressource_types = $se_config->ressource_types;
86 $indexes //= $se_config->indexes;
89 for my $rt ( @$ressource_types ) {
91 $_->{ressource_type} eq $rt ? $_ : ();
94 ressource_type => $rt,
100 indexloop => $indexloop,
103 output_html_with_http_headers $input, $cookie, $template->output;