Bug 13918 [QA Followup] - Unit Tests
[koha.git] / about.pl
blob01e941cfe880f9f705a30a34a4a8fd3644d319e7
1 #!/usr/bin/perl
3 # Copyright Pat Eyler 2003
4 # Copyright Biblibre 2006
5 # Parts Copyright Liblime 2008
6 # Parts Copyright Chris Nighswonger 2010
8 # This file is part of Koha.
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.
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.
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>.
23 use Modern::Perl;
25 use CGI qw ( -utf8 );
26 use List::MoreUtils qw/ any /;
27 use LWP::Simple;
28 use XML::Simple;
29 use Config;
31 use C4::Output;
32 use C4::Auth;
33 use C4::Context;
34 use C4::Installer;
36 use Koha;
37 use Koha::Borrowers;
38 use Koha::Config::SysPrefs;
40 #use Smart::Comments '####';
42 my $query = new CGI;
43 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
45 template_name => "about.tt",
46 query => $query,
47 type => "intranet",
48 authnotrequired => 0,
49 flagsrequired => { catalogue => 1 },
50 debug => 1,
54 my $kohaVersion = Koha::version();
55 my $osVersion = `uname -a`;
56 my $perl_path = $^X;
57 if ($^O ne 'VMS') {
58 $perl_path .= $Config{_exe} unless $perl_path =~ m/$Config{_exe}$/i;
60 my $perlVersion = $];
61 my $mysqlVersion = `mysql -V`;
62 # Get Apache version
63 my $apacheVersion = (`apache2ctl -v`)[0];
64 $apacheVersion = `httpd2 -v 2> /dev/null` unless $apacheVersion;
65 $apacheVersion = `httpd -v 2> /dev/null` unless $apacheVersion;
66 my $zebraVersion = `zebraidx -V`;
68 # Check running PSGI env
69 if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) {
70 $template->param(
71 is_psgi => 1,
72 psgi_server => ($ENV{ PLACK_ENV }) ? "Plack ($ENV{PLACK_ENV})" :
73 ($ENV{ MOD_PERL }) ? "mod_perl ($ENV{MOD_PERL})" :
74 'Unknown'
78 # Additional system information for warnings
79 my $prefAutoCreateAuthorities = C4::Context->preference('AutoCreateAuthorities');
80 my $prefBiblioAddsAuthorities = C4::Context->preference('BiblioAddsAuthorities');
81 my $warnPrefBiblioAddsAuthorities = ( $prefAutoCreateAuthorities && ( !$prefBiblioAddsAuthorities) );
83 my $prefEasyAnalyticalRecords = C4::Context->preference('EasyAnalyticalRecords');
84 my $prefUseControlNumber = C4::Context->preference('UseControlNumber');
85 my $warnPrefEasyAnalyticalRecords = ( $prefEasyAnalyticalRecords && $prefUseControlNumber );
86 my $warnPrefAnonymousPatron = (
87 C4::Context->preference('OPACPrivacy')
88 and not C4::Context->preference('AnonymousPatron')
91 my $anonymous_patron = Koha::Borrowers->find( C4::Context->preference('AnonymousPatron') );
92 my $warnPrefAnonymousPatron_PatronDoesNotExist = ( not $anonymous_patron and Koha::Borrowers->search({ privacy => 2 })->count );
94 my $errZebraConnection = C4::Context->Zconn("biblioserver",0)->errcode();
96 my $warnIsRootUser = (! $loggedinuser);
98 my $warnNoActiveCurrency = (! defined C4::Budgets->GetCurrency());
99 my @xml_config_warnings;
101 my $context = new C4::Context;
103 if ( ! defined C4::Context->config('zebra_bib_index_mode') ) {
104 push @xml_config_warnings, {
105 error => 'zebra_bib_index_mode_warn'
107 if ($context->{'server'}->{'biblioserver'}->{'config'} !~ /zebra-biblios-dom.cfg/) {
108 push @xml_config_warnings, {
109 error => 'zebra_bib_mode_seems_grs1'
112 else {
113 push @xml_config_warnings, {
114 error => 'zebra_bib_mode_seems_dom'
117 } else {
118 push @xml_config_warnings, { error => 'zebra_bib_grs_warn' }
119 if C4::Context->config('zebra_bib_index_mode') eq 'grs1';
122 if ( (C4::Context->config('zebra_bib_index_mode') eq 'dom') &&
123 ($context->{'server'}->{'biblioserver'}->{'config'} !~ /zebra-biblios-dom.cfg/) ) {
125 push @xml_config_warnings, {
126 error => 'zebra_bib_index_mode_mismatch_warn'
130 if ( (C4::Context->config('zebra_bib_index_mode') eq 'grs1') &&
131 ($context->{'server'}->{'biblioserver'}->{'config'} =~ /zebra-biblios-dom.cfg/) ) {
133 push @xml_config_warnings, {
134 error => 'zebra_bib_index_mode_mismatch_warn'
138 if ( ! defined C4::Context->config('zebra_auth_index_mode') ) {
139 push @xml_config_warnings, {
140 error => 'zebra_auth_index_mode_warn'
142 if ($context->{'server'}->{'authorityserver'}->{'config'} !~ /zebra-authorities-dom.cfg/) {
143 push @xml_config_warnings, {
144 error => 'zebra_auth_mode_seems_grs1'
147 else {
148 push @xml_config_warnings, {
149 error => 'zebra_auth_mode_seems_dom'
152 } else {
153 push @xml_config_warnings, { error => 'zebra_auth_grs_warn' }
154 if C4::Context->config('zebra_auth_index_mode') eq 'grs1';
157 if ( (C4::Context->config('zebra_auth_index_mode') eq 'dom') && ($context->{'server'}->{'authorityserver'}->{'config'} !~ /zebra-authorities-dom.cfg/) ) {
158 push @xml_config_warnings, {
159 error => 'zebra_auth_index_mode_mismatch_warn'
163 if ( (C4::Context->config('zebra_auth_index_mode') eq 'grs1') && ($context->{'server'}->{'authorityserver'}->{'config'} =~ /zebra-authorities-dom.cfg/) ) {
164 push @xml_config_warnings, {
165 error => 'zebra_auth_index_mode_mismatch_warn'
169 if ( ! defined C4::Context->config('log4perl_conf') ) {
170 push @xml_config_warnings, {
171 error => 'log4perl_entry_missing'
175 if ( ! defined C4::Context->config('upload_path') ) {
176 if ( Koha::Config::SysPrefs->find('OPACBaseURL')->value ) {
177 # OPACBaseURL seems to be set
178 push @xml_config_warnings, {
179 error => 'uploadpath_entry_missing'
181 } else {
182 push @xml_config_warnings, {
183 error => 'uploadpath_and_opacbaseurl_entry_missing'
188 # Test QueryParser configuration sanity
189 if ( C4::Context->preference( 'UseQueryParser' ) ) {
190 # Get the QueryParser configuration file name
191 my $queryparser_file = C4::Context->config( 'queryparser_config' );
192 my $queryparser_fallback_file = '/etc/koha/searchengine/queryparser.yaml';
193 # Check QueryParser is functional
194 my $QParser = C4::Context->queryparser();
195 my $queryparser_error = {};
196 if ( ! defined $QParser || ref($QParser) ne 'Koha::QueryParser::Driver::PQF' ) {
197 # Error initializing the QueryParser object
198 # Get the used queryparser.yaml file path to report the user
199 $queryparser_error->{ fallback } = ( defined $queryparser_file ) ? 0 : 1;
200 $queryparser_error->{ file } = ( defined $queryparser_file )
201 ? $queryparser_file
202 : $queryparser_fallback_file;
203 # Report error data to the template
204 $template->param( QueryParserError => $queryparser_error );
205 } else {
206 # Check for an absent queryparser_config entry in koha-conf.xml
207 if ( ! defined $queryparser_file ) {
208 # Not an error but a warning for the missing entry in koha-conf-xml
209 push @xml_config_warnings, {
210 error => 'queryparser_entry_missing',
211 file => $queryparser_fallback_file
217 # Test Zebra facets configuration
218 if ( !defined C4::Context->config('use_zebra_facets') ) {
219 push @xml_config_warnings, { error => 'use_zebra_facets_entry_missing' };
220 } else {
221 if ( C4::Context->config('use_zebra_facets') &&
222 C4::Context->config('zebra_bib_index_mode') ) {
223 # use_zebra_facets works with DOM
224 push @xml_config_warnings, {
225 error => 'use_zebra_facets_needs_dom'
226 } if C4::Context->config('zebra_bib_index_mode') ne 'dom' ;
230 # Sco Patron should not contain any other perms than circulate => self_checkout
231 if ( C4::Context->preference('WebBasedSelfCheck')
232 and C4::Context->preference('AutoSelfCheckAllowed')
234 my $userid = C4::Context->preference('AutoSelfCheckID');
235 my $all_permissions = C4::Auth::get_user_subpermissions( $userid );
236 my ( $has_self_checkout_perm, $has_other_permissions );
237 while ( my ( $module, $permissions ) = each %$all_permissions ) {
238 if ( $module eq 'circulate' ) {
239 while ( my ( $permission, $flag ) = each %$permissions ) {
240 if ( $permission eq 'self_checkout' ) {
241 $has_self_checkout_perm = 1;
242 } else {
243 $has_other_permissions = 1;
246 } else {
247 $has_other_permissions = 1;
250 $template->param(
251 AutoSelfCheckPatronDoesNotHaveSelfCheckPerm => not ( $has_self_checkout_perm ),
252 AutoSelfCheckPatronHasTooManyPerm => $has_other_permissions,
258 $template->param(
259 kohaVersion => $kohaVersion,
260 osVersion => $osVersion,
261 perlPath => $perl_path,
262 perlVersion => $perlVersion,
263 perlIncPath => [ map { perlinc => $_ }, @INC ],
264 mysqlVersion => $mysqlVersion,
265 apacheVersion => $apacheVersion,
266 zebraVersion => $zebraVersion,
267 prefBiblioAddsAuthorities => $prefBiblioAddsAuthorities,
268 prefAutoCreateAuthorities => $prefAutoCreateAuthorities,
269 warnPrefBiblioAddsAuthorities => $warnPrefBiblioAddsAuthorities,
270 warnPrefEasyAnalyticalRecords => $warnPrefEasyAnalyticalRecords,
271 warnPrefAnonymousPatron => $warnPrefAnonymousPatron,
272 warnPrefAnonymousPatron_PatronDoesNotExist => $warnPrefAnonymousPatron_PatronDoesNotExist,
273 errZebraConnection => $errZebraConnection,
274 warnIsRootUser => $warnIsRootUser,
275 warnNoActiveCurrency => $warnNoActiveCurrency,
276 xml_config_warnings => \@xml_config_warnings,
279 my @components = ();
281 my $perl_modules = C4::Installer::PerlModules->new;
282 $perl_modules->version_info;
284 my @pm_types = qw(missing_pm upgrade_pm current_pm);
286 foreach my $pm_type(@pm_types) {
287 my $modules = $perl_modules->get_attr($pm_type);
288 foreach (@$modules) {
289 my ($module, $stats) = each %$_;
290 push(
291 @components,
293 name => $module,
294 version => $stats->{'cur_ver'},
295 missing => ($pm_type eq 'missing_pm' ? 1 : 0),
296 upgrade => ($pm_type eq 'upgrade_pm' ? 1 : 0),
297 current => ($pm_type eq 'current_pm' ? 1 : 0),
298 require => $stats->{'required'},
299 reqversion => $stats->{'min_ver'},
305 @components = sort {$a->{'name'} cmp $b->{'name'}} @components;
307 my $counter=0;
308 my $row = [];
309 my $table = [];
310 foreach (@components) {
311 push (@$row, $_);
312 unless (++$counter % 4) {
313 push (@$table, {row => $row});
314 $row = [];
317 # Processing the last line (if there are any modules left)
318 if (scalar(@$row) > 0) {
319 # Extending $row to the table size
320 $$row[3] = '';
321 # Pushing the last line
322 push (@$table, {row => $row});
324 ## ## $table
326 $template->param( table => $table );
329 ## ------------------------------------------
330 ## Koha time line code
332 #get file location
333 my $docdir;
334 if ( defined C4::Context->config('docdir') ) {
335 $docdir = C4::Context->config('docdir');
336 } else {
337 # if no <docdir> is defined in koha-conf.xml, use the default location
338 # this is a work-around to stop breakage on upgraded Kohas, bug 8911
339 $docdir = C4::Context->config('intranetdir') . '/docs';
342 if ( open( my $file, "<:encoding(UTF-8)", "$docdir" . "/history.txt" ) ) {
344 my $i = 0;
346 my @rows2 = ();
347 my $row2 = [];
349 my @lines = <$file>;
350 close($file);
352 shift @lines; #remove header row
354 foreach (@lines) {
355 my ( $date, $desc, $tag ) = split(/\t/);
356 if(!$desc && $date=~ /(?<=\d{4})\s+/) {
357 ($date, $desc)= ($`, $');
359 push(
360 @rows2,
362 date => $date,
363 desc => $desc,
368 my $table2 = [];
369 #foreach my $row2 (@rows2) {
370 foreach (@rows2) {
371 push (@$row2, $_);
372 push( @$table2, { row2 => $row2 } );
373 $row2 = [];
376 $template->param( table2 => $table2 );
377 } else {
378 $template->param( timeline_read_error => 1 );
381 output_html_with_http_headers $query, $cookie, $template->output;