Bug 14006: about.pl checks the wrong zebra index mode
[koha-equinox.git] / about.pl
1 #!/usr/bin/perl
2
3 # Copyright Pat Eyler 2003
4 # Copyright Biblibre 2006
5 # Parts Copyright Liblime 2008
6 # Parts Copyright Chris Nighswonger 2010
7 #
8 # This file is part of Koha.
9 #
10 # Koha is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
14 #
15 # Koha is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22
23 use strict;
24 use warnings;
25
26 use CGI qw ( -utf8 );
27 use LWP::Simple;
28 use XML::Simple;
29 use Config;
30
31 use C4::Output;
32 use C4::Auth;
33 use C4::Context;
34 use C4::Installer;
35
36 #use Smart::Comments '####';
37
38 my $query = new CGI;
39 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
40     {
41         template_name   => "about.tt",
42         query           => $query,
43         type            => "intranet",
44         authnotrequired => 0,
45         flagsrequired   => { catalogue => 1 },
46         debug           => 1,
47     }
48 );
49
50 my $kohaVersion   = C4::Context::KOHAVERSION;
51 my $osVersion     = `uname -a`;
52 my $perl_path = $^X;
53 if ($^O ne 'VMS') {
54     $perl_path .= $Config{_exe} unless $perl_path =~ m/$Config{_exe}$/i;
55 }
56 my $perlVersion   = $];
57 my $mysqlVersion  = `mysql -V`;
58 my $apacheVersion = `httpd -v 2> /dev/null`;
59 $apacheVersion = `httpd2 -v 2> /dev/null` unless $apacheVersion;
60 $apacheVersion = (`/usr/sbin/apache2 -V`)[0] unless $apacheVersion;
61 my $zebraVersion = `zebraidx -V`;
62
63 # Additional system information for warnings
64 my $prefAutoCreateAuthorities = C4::Context->preference('AutoCreateAuthorities');
65 my $prefBiblioAddsAuthorities = C4::Context->preference('BiblioAddsAuthorities');
66 my $warnPrefBiblioAddsAuthorities = ( $prefAutoCreateAuthorities && ( !$prefBiblioAddsAuthorities) );
67
68 my $prefEasyAnalyticalRecords  = C4::Context->preference('EasyAnalyticalRecords');
69 my $prefUseControlNumber  = C4::Context->preference('UseControlNumber');
70 my $warnPrefEasyAnalyticalRecords  = ( $prefEasyAnalyticalRecords  && $prefUseControlNumber );
71 my $warnPrefAnonymousPatron = (
72     C4::Context->preference('OPACPrivacy')
73         and not C4::Context->preference('AnonymousPatron')
74 );
75
76 my $errZebraConnection = C4::Context->Zconn("biblioserver",0)->errcode();
77
78 my $warnIsRootUser   = (! $loggedinuser);
79
80 my $warnNoActiveCurrency = (! defined C4::Budgets->GetCurrency());
81 my @xml_config_warnings;
82
83 my $context = new C4::Context;
84
85 if ( ! defined C4::Context->config('zebra_bib_index_mode') ) {
86     push @xml_config_warnings, {
87         error => 'zebra_bib_index_mode_warn'
88     };
89     if ($context->{'server'}->{'biblioserver'}->{'config'} !~ /zebra-biblios-dom.cfg/) {
90         push @xml_config_warnings, {
91             error => 'zebra_bib_mode_seems_grs1'
92         };
93     }
94     else {
95         push @xml_config_warnings, {
96             error => 'zebra_bib_mode_seems_dom'
97         };
98     }
99 } else {
100     push @xml_config_warnings, { error => 'zebra_bib_grs_warn' }
101         if C4::Context->config('zebra_bib_index_mode') eq 'grs1';
102 }
103
104 if ( (C4::Context->config('zebra_bib_index_mode') eq 'dom') &&
105      ($context->{'server'}->{'biblioserver'}->{'config'} !~ /zebra-biblios-dom.cfg/) ) {
106
107     push @xml_config_warnings, {
108         error => 'zebra_bib_index_mode_mismatch_warn'
109     };
110 }
111
112 if ( (C4::Context->config('zebra_bib_index_mode') eq 'grs1') &&
113      ($context->{'server'}->{'biblioserver'}->{'config'} =~ /zebra-biblios-dom.cfg/) ) {
114
115     push @xml_config_warnings, {
116         error => 'zebra_bib_index_mode_mismatch_warn'
117     };
118 }
119
120 if ( ! defined C4::Context->config('zebra_auth_index_mode') ) {
121     push @xml_config_warnings, {
122         error => 'zebra_auth_index_mode_warn'
123     };
124     if ($context->{'server'}->{'authorityserver'}->{'config'} !~ /zebra-authorities-dom.cfg/) {
125         push @xml_config_warnings, {
126             error => 'zebra_auth_mode_seems_grs1'
127         };
128     }
129     else {
130         push @xml_config_warnings, {
131             error => 'zebra_auth_mode_seems_dom'
132         };
133     }
134 } else {
135     push @xml_config_warnings, { error => 'zebra_auth_grs_warn' }
136         if C4::Context->config('zebra_auth_index_mode') eq 'grs1';
137 }
138
139 if ( (C4::Context->config('zebra_auth_index_mode') eq 'dom') && ($context->{'server'}->{'authorityserver'}->{'config'} !~ /zebra-authorities-dom.cfg/) ) {
140     push @xml_config_warnings, {
141         error => 'zebra_auth_index_mode_mismatch_warn'
142     };
143 }
144
145 if ( (C4::Context->config('zebra_auth_index_mode') eq 'grs1') && ($context->{'server'}->{'authorityserver'}->{'config'} =~ /zebra-authorities-dom.cfg/) ) {
146     push @xml_config_warnings, {
147         error => 'zebra_auth_index_mode_mismatch_warn'
148     };
149 }
150
151 # Test QueryParser configuration sanity
152 if ( C4::Context->preference( 'UseQueryParser' ) ) {
153     # Get the QueryParser configuration file name
154     my $queryparser_file          = C4::Context->config( 'queryparser_config' );
155     my $queryparser_fallback_file = '/etc/koha/searchengine/queryparser.yaml';
156     # Check QueryParser is functional
157     my $QParser = C4::Context->queryparser();
158     my $queryparser_error = {};
159     if ( ! defined $QParser || ref($QParser) ne 'Koha::QueryParser::Driver::PQF' ) {
160         # Error initializing the QueryParser object
161         # Get the used queryparser.yaml file path to report the user
162         $queryparser_error->{ fallback } = ( defined $queryparser_file ) ? 0 : 1;
163         $queryparser_error->{ file }     = ( defined $queryparser_file )
164                                                 ? $queryparser_file
165                                                 : $queryparser_fallback_file;
166         # Report error data to the template
167         $template->param( QueryParserError => $queryparser_error );
168     } else {
169         # Check for an absent queryparser_config entry in koha-conf.xml
170         if ( ! defined $queryparser_file ) {
171             # Not an error but a warning for the missing entry in koha-conf-xml
172             push @xml_config_warnings, {
173                     error => 'queryparser_entry_missing',
174                     file  => $queryparser_fallback_file
175             };
176         }
177     }
178 }
179
180 # Test Zebra facets configuration
181 if ( !defined C4::Context->config('use_zebra_facets') ) {
182     push @xml_config_warnings, { error => 'use_zebra_facets_entry_missing' };
183 } else {
184     if ( C4::Context->config('use_zebra_facets') &&
185          C4::Context->config('zebra_bib_index_mode') ) {
186         # use_zebra_facets works with DOM
187         push @xml_config_warnings, {
188             error => 'use_zebra_facets_needs_dom'
189         } if C4::Context->config('zebra_bib_index_mode') ne 'dom' ;
190     }
191 }
192
193 $template->param(
194     kohaVersion   => $kohaVersion,
195     osVersion     => $osVersion,
196     perlPath      => $perl_path,
197     perlVersion   => $perlVersion,
198     perlIncPath   => [ map { perlinc => $_ }, @INC ],
199     mysqlVersion  => $mysqlVersion,
200     apacheVersion => $apacheVersion,
201     zebraVersion  => $zebraVersion,
202     prefBiblioAddsAuthorities => $prefBiblioAddsAuthorities,
203     prefAutoCreateAuthorities => $prefAutoCreateAuthorities,
204     warnPrefBiblioAddsAuthorities => $warnPrefBiblioAddsAuthorities,
205     warnPrefEasyAnalyticalRecords  => $warnPrefEasyAnalyticalRecords,
206     warnPrefAnonymousPatron => $warnPrefAnonymousPatron,
207     errZebraConnection => $errZebraConnection,
208     warnIsRootUser => $warnIsRootUser,
209     warnNoActiveCurrency => $warnNoActiveCurrency,
210     xml_config_warnings => \@xml_config_warnings,
211 );
212
213 my @components = ();
214
215 my $perl_modules = C4::Installer::PerlModules->new;
216 $perl_modules->version_info;
217
218 my @pm_types = qw(missing_pm upgrade_pm current_pm);
219
220 foreach my $pm_type(@pm_types) {
221     my $modules = $perl_modules->get_attr($pm_type);
222     foreach (@$modules) {
223         my ($module, $stats) = each %$_;
224         push(
225             @components,
226             {
227                 name    => $module,
228                 version => $stats->{'cur_ver'},
229                 missing => ($pm_type eq 'missing_pm' ? 1 : 0),
230                 upgrade => ($pm_type eq 'upgrade_pm' ? 1 : 0),
231                 current => ($pm_type eq 'current_pm' ? 1 : 0),
232                 require => $stats->{'required'},
233                 reqversion => $stats->{'min_ver'},
234             }
235         );
236     }
237 }
238
239 @components = sort {$a->{'name'} cmp $b->{'name'}} @components;
240
241 my $counter=0;
242 my $row = [];
243 my $table = [];
244 foreach (@components) {
245     push (@$row, $_);
246     unless (++$counter % 4) {
247         push (@$table, {row => $row});
248         $row = [];
249     }
250 }
251 # Processing the last line (if there are any modules left)
252 if (scalar(@$row) > 0) {
253     # Extending $row to the table size
254     $$row[3] = '';
255     # Pushing the last line
256     push (@$table, {row => $row});
257 }
258 ## ## $table
259
260 $template->param( table => $table );
261
262
263 ## ------------------------------------------
264 ## Koha time line code
265
266 #get file location
267 my $docdir;
268 if ( defined C4::Context->config('docdir') ) {
269     $docdir = C4::Context->config('docdir');
270 } else {
271     # if no <docdir> is defined in koha-conf.xml, use the default location
272     # this is a work-around to stop breakage on upgraded Kohas, bug 8911
273     $docdir = C4::Context->config('intranetdir') . '/docs';
274 }
275
276 if ( open( my $file, "<:encoding(UTF-8)", "$docdir" . "/history.txt" ) ) {
277
278     my $i = 0;
279
280     my @rows2 = ();
281     my $row2  = [];
282
283     my @lines = <$file>;
284     close($file);
285
286     shift @lines; #remove header row
287
288     foreach (@lines) {
289         my ( $date, $desc, $tag ) = split(/\t/);
290         if(!$desc && $date=~ /(?<=\d{4})\s+/) {
291             ($date, $desc)= ($`, $');
292         }
293         push(
294             @rows2,
295             {
296                 date => $date,
297                 desc => $desc,
298             }
299         );
300     }
301
302     my $table2 = [];
303     #foreach my $row2 (@rows2) {
304     foreach  (@rows2) {
305         push (@$row2, $_);
306         push( @$table2, { row2 => $row2 } );
307         $row2 = [];
308     }
309
310     $template->param( table2 => $table2 );
311 } else {
312     $template->param( timeline_read_error => 1 );
313 }
314
315 output_html_with_http_headers $query, $cookie, $template->output;