Bug 11431: (QA followup) Unit Tests
[koha.git] / about.pl
blob4c273666ce48436898b15dae5dfa5fe4ff3ba212
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 strict;
24 use warnings;
26 use CGI qw ( -utf8 );
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 # Additional system information for warnings
69 my $prefAutoCreateAuthorities = C4::Context->preference('AutoCreateAuthorities');
70 my $prefBiblioAddsAuthorities = C4::Context->preference('BiblioAddsAuthorities');
71 my $warnPrefBiblioAddsAuthorities = ( $prefAutoCreateAuthorities && ( !$prefBiblioAddsAuthorities) );
73 my $prefEasyAnalyticalRecords = C4::Context->preference('EasyAnalyticalRecords');
74 my $prefUseControlNumber = C4::Context->preference('UseControlNumber');
75 my $warnPrefEasyAnalyticalRecords = ( $prefEasyAnalyticalRecords && $prefUseControlNumber );
76 my $warnPrefAnonymousPatron = (
77 C4::Context->preference('OPACPrivacy')
78 and not C4::Context->preference('AnonymousPatron')
81 my $anonymous_patron = Koha::Borrowers->find( C4::Context->preference('AnonymousPatron') );
82 my $warnPrefAnonymousPatron_PatronDoesNotExist = ( not $anonymous_patron and Koha::Borrowers->search({ privacy => 2 })->count );
84 my $errZebraConnection = C4::Context->Zconn("biblioserver",0)->errcode();
86 my $warnIsRootUser = (! $loggedinuser);
88 my $warnNoActiveCurrency = (! defined C4::Budgets->GetCurrency());
89 my @xml_config_warnings;
91 my $context = new C4::Context;
93 if ( ! defined C4::Context->config('zebra_bib_index_mode') ) {
94 push @xml_config_warnings, {
95 error => 'zebra_bib_index_mode_warn'
97 if ($context->{'server'}->{'biblioserver'}->{'config'} !~ /zebra-biblios-dom.cfg/) {
98 push @xml_config_warnings, {
99 error => 'zebra_bib_mode_seems_grs1'
102 else {
103 push @xml_config_warnings, {
104 error => 'zebra_bib_mode_seems_dom'
107 } else {
108 push @xml_config_warnings, { error => 'zebra_bib_grs_warn' }
109 if C4::Context->config('zebra_bib_index_mode') eq 'grs1';
112 if ( (C4::Context->config('zebra_bib_index_mode') eq 'dom') &&
113 ($context->{'server'}->{'biblioserver'}->{'config'} !~ /zebra-biblios-dom.cfg/) ) {
115 push @xml_config_warnings, {
116 error => 'zebra_bib_index_mode_mismatch_warn'
120 if ( (C4::Context->config('zebra_bib_index_mode') eq 'grs1') &&
121 ($context->{'server'}->{'biblioserver'}->{'config'} =~ /zebra-biblios-dom.cfg/) ) {
123 push @xml_config_warnings, {
124 error => 'zebra_bib_index_mode_mismatch_warn'
128 if ( ! defined C4::Context->config('zebra_auth_index_mode') ) {
129 push @xml_config_warnings, {
130 error => 'zebra_auth_index_mode_warn'
132 if ($context->{'server'}->{'authorityserver'}->{'config'} !~ /zebra-authorities-dom.cfg/) {
133 push @xml_config_warnings, {
134 error => 'zebra_auth_mode_seems_grs1'
137 else {
138 push @xml_config_warnings, {
139 error => 'zebra_auth_mode_seems_dom'
142 } else {
143 push @xml_config_warnings, { error => 'zebra_auth_grs_warn' }
144 if C4::Context->config('zebra_auth_index_mode') eq 'grs1';
147 if ( (C4::Context->config('zebra_auth_index_mode') eq 'dom') && ($context->{'server'}->{'authorityserver'}->{'config'} !~ /zebra-authorities-dom.cfg/) ) {
148 push @xml_config_warnings, {
149 error => 'zebra_auth_index_mode_mismatch_warn'
153 if ( (C4::Context->config('zebra_auth_index_mode') eq 'grs1') && ($context->{'server'}->{'authorityserver'}->{'config'} =~ /zebra-authorities-dom.cfg/) ) {
154 push @xml_config_warnings, {
155 error => 'zebra_auth_index_mode_mismatch_warn'
159 if ( ! defined C4::Context->config('log4perl_conf') ) {
160 push @xml_config_warnings, {
161 error => 'log4perl_entry_missing'
165 if ( ! defined C4::Context->config('upload_path') ) {
166 if ( Koha::Config::SysPrefs->find('OPACBaseURL')->value ) {
167 # OPACBaseURL seems to be set
168 push @xml_config_warnings, {
169 error => 'uploadpath_entry_missing'
171 } else {
172 push @xml_config_warnings, {
173 error => 'uploadpath_and_opacbaseurl_entry_missing'
178 # Test QueryParser configuration sanity
179 if ( C4::Context->preference( 'UseQueryParser' ) ) {
180 # Get the QueryParser configuration file name
181 my $queryparser_file = C4::Context->config( 'queryparser_config' );
182 my $queryparser_fallback_file = '/etc/koha/searchengine/queryparser.yaml';
183 # Check QueryParser is functional
184 my $QParser = C4::Context->queryparser();
185 my $queryparser_error = {};
186 if ( ! defined $QParser || ref($QParser) ne 'Koha::QueryParser::Driver::PQF' ) {
187 # Error initializing the QueryParser object
188 # Get the used queryparser.yaml file path to report the user
189 $queryparser_error->{ fallback } = ( defined $queryparser_file ) ? 0 : 1;
190 $queryparser_error->{ file } = ( defined $queryparser_file )
191 ? $queryparser_file
192 : $queryparser_fallback_file;
193 # Report error data to the template
194 $template->param( QueryParserError => $queryparser_error );
195 } else {
196 # Check for an absent queryparser_config entry in koha-conf.xml
197 if ( ! defined $queryparser_file ) {
198 # Not an error but a warning for the missing entry in koha-conf-xml
199 push @xml_config_warnings, {
200 error => 'queryparser_entry_missing',
201 file => $queryparser_fallback_file
207 # Test Zebra facets configuration
208 if ( !defined C4::Context->config('use_zebra_facets') ) {
209 push @xml_config_warnings, { error => 'use_zebra_facets_entry_missing' };
210 } else {
211 if ( C4::Context->config('use_zebra_facets') &&
212 C4::Context->config('zebra_bib_index_mode') ) {
213 # use_zebra_facets works with DOM
214 push @xml_config_warnings, {
215 error => 'use_zebra_facets_needs_dom'
216 } if C4::Context->config('zebra_bib_index_mode') ne 'dom' ;
220 # Sco Patron should not contain any other perms than circulate => self_checkout
221 if ( C4::Context->preference('WebBasedSelfCheck')
222 and C4::Context->preference('AutoSelfCheckAllowed')
224 my $userid = C4::Context->preference('AutoSelfCheckID');
225 my $all_permissions = C4::Auth::get_user_subpermissions( $userid );
226 my ( $has_self_checkout_perm, $has_other_permissions );
227 while ( my ( $module, $permissions ) = each %$all_permissions ) {
228 if ( $module eq 'circulate' ) {
229 while ( my ( $permission, $flag ) = each %$permissions ) {
230 if ( $permission eq 'self_checkout' ) {
231 $has_self_checkout_perm = 1;
232 } else {
233 $has_other_permissions = 1;
236 } else {
237 $has_other_permissions = 1;
240 $template->param(
241 AutoSelfCheckPatronDoesNotHaveSelfCheckPerm => not ( $has_self_checkout_perm ),
242 AutoSelfCheckPatronHasTooManyPerm => $has_other_permissions,
248 $template->param(
249 kohaVersion => $kohaVersion,
250 osVersion => $osVersion,
251 perlPath => $perl_path,
252 perlVersion => $perlVersion,
253 perlIncPath => [ map { perlinc => $_ }, @INC ],
254 mysqlVersion => $mysqlVersion,
255 apacheVersion => $apacheVersion,
256 zebraVersion => $zebraVersion,
257 prefBiblioAddsAuthorities => $prefBiblioAddsAuthorities,
258 prefAutoCreateAuthorities => $prefAutoCreateAuthorities,
259 warnPrefBiblioAddsAuthorities => $warnPrefBiblioAddsAuthorities,
260 warnPrefEasyAnalyticalRecords => $warnPrefEasyAnalyticalRecords,
261 warnPrefAnonymousPatron => $warnPrefAnonymousPatron,
262 warnPrefAnonymousPatron_PatronDoesNotExist => $warnPrefAnonymousPatron_PatronDoesNotExist,
263 errZebraConnection => $errZebraConnection,
264 warnIsRootUser => $warnIsRootUser,
265 warnNoActiveCurrency => $warnNoActiveCurrency,
266 xml_config_warnings => \@xml_config_warnings,
269 my @components = ();
271 my $perl_modules = C4::Installer::PerlModules->new;
272 $perl_modules->version_info;
274 my @pm_types = qw(missing_pm upgrade_pm current_pm);
276 foreach my $pm_type(@pm_types) {
277 my $modules = $perl_modules->get_attr($pm_type);
278 foreach (@$modules) {
279 my ($module, $stats) = each %$_;
280 push(
281 @components,
283 name => $module,
284 version => $stats->{'cur_ver'},
285 missing => ($pm_type eq 'missing_pm' ? 1 : 0),
286 upgrade => ($pm_type eq 'upgrade_pm' ? 1 : 0),
287 current => ($pm_type eq 'current_pm' ? 1 : 0),
288 require => $stats->{'required'},
289 reqversion => $stats->{'min_ver'},
295 @components = sort {$a->{'name'} cmp $b->{'name'}} @components;
297 my $counter=0;
298 my $row = [];
299 my $table = [];
300 foreach (@components) {
301 push (@$row, $_);
302 unless (++$counter % 4) {
303 push (@$table, {row => $row});
304 $row = [];
307 # Processing the last line (if there are any modules left)
308 if (scalar(@$row) > 0) {
309 # Extending $row to the table size
310 $$row[3] = '';
311 # Pushing the last line
312 push (@$table, {row => $row});
314 ## ## $table
316 $template->param( table => $table );
319 ## ------------------------------------------
320 ## Koha time line code
322 #get file location
323 my $docdir;
324 if ( defined C4::Context->config('docdir') ) {
325 $docdir = C4::Context->config('docdir');
326 } else {
327 # if no <docdir> is defined in koha-conf.xml, use the default location
328 # this is a work-around to stop breakage on upgraded Kohas, bug 8911
329 $docdir = C4::Context->config('intranetdir') . '/docs';
332 if ( open( my $file, "<:encoding(UTF-8)", "$docdir" . "/history.txt" ) ) {
334 my $i = 0;
336 my @rows2 = ();
337 my $row2 = [];
339 my @lines = <$file>;
340 close($file);
342 shift @lines; #remove header row
344 foreach (@lines) {
345 my ( $date, $desc, $tag ) = split(/\t/);
346 if(!$desc && $date=~ /(?<=\d{4})\s+/) {
347 ($date, $desc)= ($`, $');
349 push(
350 @rows2,
352 date => $date,
353 desc => $desc,
358 my $table2 = [];
359 #foreach my $row2 (@rows2) {
360 foreach (@rows2) {
361 push (@$row2, $_);
362 push( @$table2, { row2 => $row2 } );
363 $row2 = [];
366 $template->param( table2 => $table2 );
367 } else {
368 $template->param( timeline_read_error => 1 );
371 output_html_with_http_headers $query, $cookie, $template->output;