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>.
26 use DateTime::TimeZone;
29 use List::MoreUtils qw/ any /;
31 use Module::Load::Conditional qw(can_load);
34 use Search::Elasticsearch;
36 use YAML qw/LoadFile/;
41 use C4::Installer::PerlModules;
44 use Koha::DateUtils qw(dt_from_string output_pref);
45 use Koha::Acquisition::Currencies;
46 use Koha::Patron::Categories;
49 use Koha::Config::SysPrefs;
50 use Koha::Illrequest::Config;
51 use Koha::SearchEngine::Elasticsearch;
54 use C4::Members::Statistics;
57 #use Smart::Comments '####';
60 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
62 template_name => "about.tt",
65 flagsrequired => { catalogue => 1 },
70 my $config_timezone = C4::Context->config('timezone') // '';
71 my $config_invalid = !DateTime::TimeZone->is_valid_name( $config_timezone );
72 my $env_timezone = $ENV{TZ} // '';
73 my $env_invalid = !DateTime::TimeZone->is_valid_name( $env_timezone );
74 my $actual_bad_tz_fallback = 0;
76 if ( $config_timezone ne '' &&
79 $actual_bad_tz_fallback = 1;
81 elsif ( $config_timezone eq '' &&
82 $env_timezone ne '' &&
84 # No config, but bad ENV{TZ}
85 $actual_bad_tz_fallback = 1;
89 actual => C4::Context->tz->name,
90 actual_bad_tz_fallback => $actual_bad_tz_fallback,
91 config => $config_timezone,
92 config_invalid => $config_invalid,
93 environment => $env_timezone,
94 environment_invalid => $env_invalid
98 my $log4perl_config = C4::Context->config("log4perl_conf");
100 if ( ! $log4perl_config ) {
101 push @log4perl_errors, 'missing_config_entry'
104 my @lines = read_file($log4perl_config) or push @log4perl_errors, 'cannot_read_config_file';
105 for my $line ( @lines ) {
106 next unless $line =~ m|log4perl.appender.\w+.filename=(.*)|;
107 push @log4perl_errors, 'logfile_not_writable' unless -w $1;
110 eval {Koha::Logger->get};
111 push @log4perl_errors, 'cannot_init_module' and warn $@ if $@;
112 $template->param( log4perl_errors => @log4perl_errors );
116 time_zone => $time_zone,
117 current_date_and_time => output_pref({ dt => dt_from_string(), dateformat => 'iso' })
122 $perl_path .= $Config{_exe} unless $perl_path =~ m/$Config{_exe}$/i;
125 my $zebraVersion = `zebraidx -V`;
127 # Check running PSGI env
128 if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) {
131 psgi_server => ($ENV{ PLACK_ENV }) ? "Plack ($ENV{PLACK_ENV})" :
132 ($ENV{ MOD_PERL }) ? "mod_perl ($ENV{MOD_PERL})" :
137 # Memcached configuration
138 my $memcached_servers = $ENV{MEMCACHED_SERVERS} || C4::Context->config('memcached_servers');
139 my $memcached_namespace = $ENV{MEMCACHED_NAMESPACE} || C4::Context->config('memcached_namespace') // 'koha';
141 my $cache = Koha::Caches->get_instance;
142 my $effective_caching_method = ref($cache->cache);
143 # Memcached may have been running when plack has been initialized but could have been stopped since
144 # FIXME What are the consequences of that??
145 my $is_memcached_still_active = $cache->set_in_cache('test_for_about_page', "just a simple value");
147 my $where_is_memcached_config = 'nowhere';
148 if ( $ENV{MEMCACHED_SERVERS} and C4::Context->config('memcached_servers') ) {
149 $where_is_memcached_config = 'both';
150 } elsif ( $ENV{MEMCACHED_SERVERS} and not C4::Context->config('memcached_servers') ) {
151 $where_is_memcached_config = 'ENV_only';
152 } elsif ( C4::Context->config('memcached_servers') ) {
153 $where_is_memcached_config = 'config_only';
157 effective_caching_method => $effective_caching_method,
158 memcached_servers => $memcached_servers,
159 memcached_namespace => $memcached_namespace,
160 is_memcached_still_active => $is_memcached_still_active,
161 where_is_memcached_config => $where_is_memcached_config,
162 memcached_running => Koha::Caches->get_instance->memcached_cache,
165 # Additional system information for warnings
167 my $warnStatisticsFieldsError;
168 my $prefStatisticsFields = C4::Context->preference('StatisticsFields');
169 if ($prefStatisticsFields) {
170 $warnStatisticsFieldsError = $prefStatisticsFields
171 unless ( $prefStatisticsFields eq C4::Members::Statistics->get_fields() );
174 my $prefAutoCreateAuthorities = C4::Context->preference('AutoCreateAuthorities');
175 my $prefBiblioAddsAuthorities = C4::Context->preference('BiblioAddsAuthorities');
176 my $warnPrefBiblioAddsAuthorities = ( $prefAutoCreateAuthorities && ( !$prefBiblioAddsAuthorities) );
178 my $prefEasyAnalyticalRecords = C4::Context->preference('EasyAnalyticalRecords');
179 my $prefUseControlNumber = C4::Context->preference('UseControlNumber');
180 my $warnPrefEasyAnalyticalRecords = ( $prefEasyAnalyticalRecords && $prefUseControlNumber );
182 my $AnonymousPatron = C4::Context->preference('AnonymousPatron');
183 my $warnPrefAnonymousPatronOPACPrivacy = (
184 C4::Context->preference('OPACPrivacy')
185 and not $AnonymousPatron
187 my $warnPrefAnonymousPatronAnonSuggestions = (
188 C4::Context->preference('AnonSuggestions')
189 and not $AnonymousPatron
192 my $anonymous_patron = Koha::Patrons->find( $AnonymousPatron );
193 my $warnPrefAnonymousPatronAnonSuggestions_PatronDoesNotExist = ( $AnonymousPatron && C4::Context->preference('AnonSuggestions') && not $anonymous_patron );
195 my $warnPrefAnonymousPatronOPACPrivacy_PatronDoesNotExist = ( not $anonymous_patron and Koha::Patrons->search({ privacy => 2 })->count );
197 my $errZebraConnection = C4::Context->Zconn("biblioserver",0)->errcode();
199 my $warnIsRootUser = (! $loggedinuser);
201 my $warnNoActiveCurrency = (! defined Koha::Acquisition::Currencies->get_active);
203 my @xml_config_warnings;
205 my $context = new C4::Context;
207 if ( C4::Context->config('zebra_bib_index_mode')
208 and C4::Context->config('zebra_bib_index_mode') eq 'grs1' )
210 push @xml_config_warnings, { error => 'zebra_bib_index_mode_is_grs1' };
213 if ( C4::Context->config('zebra_auth_index_mode')
214 and C4::Context->config('zebra_auth_index_mode') eq 'grs1' )
216 push @xml_config_warnings, { error => 'zebra_auth_index_mode_is_grs1' };
219 if( ( C4::Context->config('zebra_auth_index_mode')
220 and C4::Context->config('zebra_auth_index_mode') eq 'dom' )
221 && ( $context->{'server'}->{'authorityserver'}->{'config'} !~ /zebra-authorities-dom.cfg/ ) )
223 push @xml_config_warnings, {
224 error => 'zebra_auth_index_mode_mismatch_warn'
228 if ( ! defined C4::Context->config('log4perl_conf') ) {
229 push @xml_config_warnings, {
230 error => 'log4perl_entry_missing'
234 if ( ! defined C4::Context->config('lockdir') ) {
235 push @xml_config_warnings, {
236 error => 'lockdir_entry_missing'
240 unless ( -w C4::Context->config('lockdir') ) {
241 push @xml_config_warnings, {
242 error => 'lockdir_not_writable',
243 lockdir => C4::Context->config('lockdir')
248 if ( ! defined C4::Context->config('upload_path') ) {
249 if ( Koha::Config::SysPrefs->find('OPACBaseURL')->value ) {
250 # OPACBaseURL seems to be set
251 push @xml_config_warnings, {
252 error => 'uploadpath_entry_missing'
255 push @xml_config_warnings, {
256 error => 'uploadpath_and_opacbaseurl_entry_missing'
261 if ( ! C4::Context->config('tmp_path') ) {
262 my $temporary_directory = C4::Context::temporary_directory;
263 push @xml_config_warnings, {
264 error => 'tmp_path_missing',
265 effective_tmp_dir => $temporary_directory,
269 # Test Zebra facets configuration
270 if ( !defined C4::Context->config('use_zebra_facets') ) {
271 push @xml_config_warnings, { error => 'use_zebra_facets_entry_missing' };
275 if ( C4::Context->preference('ILLModule') ) {
276 my $warnILLConfiguration = 0;
277 my $ill_config_from_file = C4::Context->config("interlibrary_loans");
278 my $ill_config = Koha::Illrequest::Config->new;
280 my $available_ill_backends =
281 ( scalar @{ $ill_config->available_backends } > 0 );
284 if ( !$available_ill_backends ) {
285 $template->param( no_ill_backends => 1 );
286 $warnILLConfiguration = 1;
290 if ( !Koha::Patron::Categories->find($ill_config->partner_code) ) {
291 $template->param( ill_partner_code_doesnt_exist => $ill_config->partner_code );
292 $warnILLConfiguration = 1;
295 if ( !$ill_config_from_file->{partner_code} ) {
296 # partner code not defined
297 $template->param( ill_partner_code_not_defined => 1 );
298 $warnILLConfiguration = 1;
302 if ( !$ill_config_from_file->{branch} ) {
304 $template->param( ill_branch_not_defined => 1 );
305 $warnILLConfiguration = 1;
308 $template->param( warnILLConfiguration => $warnILLConfiguration );
311 if ( C4::Context->preference('SearchEngine') eq 'Elasticsearch' ) {
312 # Check ES configuration health and runtime status
320 $es_conf = Koha::SearchEngine::Elasticsearch::_read_configuration();
323 if ( ref($_) eq 'Koha::Exceptions::Config::MissingEntry' ) {
324 $template->param( elasticsearch_fatal_config_error => $_->message );
325 $es_config_error = 1;
328 if ( !$es_config_error ) {
330 my $biblios_index_name = $es_conf->{index_name} . "_" . $Koha::SearchEngine::BIBLIOS_INDEX;
331 my $authorities_index_name = $es_conf->{index_name} . "_" . $Koha::SearchEngine::AUTHORITIES_INDEX;
333 my @indexes = ($biblios_index_name, $authorities_index_name);
334 # TODO: When new indexes get added, we could have other ways to
335 # fetch the list of available indexes (e.g. plugins, etc)
336 $es_status->{nodes} = $es_conf->{nodes};
337 my $es = Search::Elasticsearch->new({ nodes => $es_conf->{nodes} });
339 foreach my $index ( @indexes ) {
342 $count = $es->indices->stats( index => $index )
343 ->{_all}{primaries}{docs}{count};
346 if ( ref($_) eq 'Search::Elasticsearch::Error::Missing' ) {
347 push @{ $es_status->{errors} }, "Index not found ($index)";
350 elsif ( ref($_) eq 'Search::Elasticsearch::Error::NoNodes' ) {
354 # TODO: when time comes, we will cover more use cases
359 push @{ $es_status->{indexes} },
361 index_name => $index,
365 $es_status->{running} = $es_running;
367 $template->param( elasticsearch_status => $es_status );
371 if ( C4::Context->preference('RESTOAuth2ClientCredentials') ) {
372 # Do we have the required deps?
373 unless ( can_load( modules => { 'Net::OAuth2::AuthorizationServer' => undef }) ) {
374 $template->param( oauth2_missing_deps => 1 );
378 # Sco Patron should not contain any other perms than circulate => self_checkout
379 if ( C4::Context->preference('WebBasedSelfCheck')
380 and C4::Context->preference('AutoSelfCheckAllowed')
382 my $userid = C4::Context->preference('AutoSelfCheckID');
383 my $all_permissions = C4::Auth::get_user_subpermissions( $userid );
384 my ( $has_self_checkout_perm, $has_other_permissions );
385 while ( my ( $module, $permissions ) = each %$all_permissions ) {
386 if ( $module eq 'self_check' ) {
387 while ( my ( $permission, $flag ) = each %$permissions ) {
388 if ( $permission eq 'self_checkout_module' ) {
389 $has_self_checkout_perm = 1;
391 $has_other_permissions = 1;
395 $has_other_permissions = 1;
399 AutoSelfCheckPatronDoesNotHaveSelfCheckPerm => not ( $has_self_checkout_perm ),
400 AutoSelfCheckPatronHasTooManyPerm => $has_other_permissions,
404 # Test YAML system preferences
405 # FIXME: This is list of current YAML formatted prefs, should by type of preference
407 "UpdateNotForLoanStatusOnCheckin",
409 "BibtexExportAdditionalFields",
410 "RisExportAdditionalFields",
411 "UpdateItemWhenLostFromHoldList",
413 "MarcItemFieldsToOrder",
414 "UpdateitemLocationOnCheckin",
418 foreach my $syspref (@yaml_prefs) {
419 my $yaml = C4::Context->preference( $syspref );
421 eval { YAML::Load( "$yaml\n\n" ); };
423 push @bad_yaml_prefs, $syspref;
427 $template->param( 'bad_yaml_prefs' => \@bad_yaml_prefs ) if @bad_yaml_prefs;
430 my $dbh = C4::Context->dbh;
431 my $patrons = $dbh->selectall_arrayref(
432 q|select b.borrowernumber from borrowers b join deletedborrowers db on b.borrowernumber=db.borrowernumber|,
435 my $biblios = $dbh->selectall_arrayref(
436 q|select b.biblionumber from biblio b join deletedbiblio db on b.biblionumber=db.biblionumber|,
439 my $items = $dbh->selectall_arrayref(
440 q|select i.itemnumber from items i join deleteditems di on i.itemnumber=di.itemnumber|,
443 my $checkouts = $dbh->selectall_arrayref(
444 q|select i.issue_id from issues i join old_issues oi on i.issue_id=oi.issue_id|,
447 my $holds = $dbh->selectall_arrayref(
448 q|select r.reserve_id from reserves r join old_reserves o on r.reserve_id=o.reserve_id|,
451 if ( @$patrons or @$biblios or @$items or @$checkouts or @$holds ) {
454 ai_patrons => $patrons,
455 ai_biblios => $biblios,
457 ai_checkouts => $checkouts,
465 my $dbh = C4::Context->dbh;
466 my $units = Koha::CirculationRules->search({ rule_name => 'lengthunit', rule_value => { -not_in => ['days', 'hours'] } });
468 if ( $units->count ) {
470 warnIssuingRules => 1,
476 # Guarantor relationships warnings
478 my $dbh = C4::Context->dbh;
479 my ($bad_relationships_count) = $dbh->selectall_arrayref(q{
482 SELECT relationship FROM borrower_relationships WHERE relationship='_bad_data'
484 SELECT relationship FROM borrowers WHERE relationship='_bad_data') a
487 $bad_relationships_count = $bad_relationships_count->[0]->[0];
489 my $existing_relationships = $dbh->selectall_arrayref(q{
490 SELECT DISTINCT(relationship)
492 SELECT relationship FROM borrower_relationships WHERE relationship IS NOT NULL
494 SELECT relationship FROM borrowers WHERE relationship IS NOT NULL) a
497 my %valid_relationships = map { $_ => 1 } split( /,|\|/, C4::Context->preference('borrowerRelationship') );
498 $valid_relationships{ _bad_data } = 1; # we handle this case in another way
500 my $wrong_relationships = [ grep { !$valid_relationships{ $_->[0] } } @{$existing_relationships} ];
501 if ( @$wrong_relationships or $bad_relationships_count ) {
504 warnRelationships => 1,
507 if ( $wrong_relationships ) {
509 wrong_relationships => $wrong_relationships
512 if ($bad_relationships_count) {
514 bad_relationships_count => $bad_relationships_count,
520 my %versions = C4::Context::get_versions();
523 kohaVersion => $versions{'kohaVersion'},
524 osVersion => $versions{'osVersion'},
525 perlPath => $perl_path,
526 perlVersion => $versions{'perlVersion'},
527 perlIncPath => [ map { perlinc => $_ }, @INC ],
528 mysqlVersion => $versions{'mysqlVersion'},
529 apacheVersion => $versions{'apacheVersion'},
530 zebraVersion => $zebraVersion,
531 prefBiblioAddsAuthorities => $prefBiblioAddsAuthorities,
532 prefAutoCreateAuthorities => $prefAutoCreateAuthorities,
533 warnPrefBiblioAddsAuthorities => $warnPrefBiblioAddsAuthorities,
534 warnPrefEasyAnalyticalRecords => $warnPrefEasyAnalyticalRecords,
535 warnPrefAnonymousPatronOPACPrivacy => $warnPrefAnonymousPatronOPACPrivacy,
536 warnPrefAnonymousPatronAnonSuggestions => $warnPrefAnonymousPatronAnonSuggestions,
537 warnPrefAnonymousPatronOPACPrivacy_PatronDoesNotExist => $warnPrefAnonymousPatronOPACPrivacy_PatronDoesNotExist,
538 warnPrefAnonymousPatronAnonSuggestions_PatronDoesNotExist => $warnPrefAnonymousPatronAnonSuggestions_PatronDoesNotExist,
539 errZebraConnection => $errZebraConnection,
540 warnIsRootUser => $warnIsRootUser,
541 warnNoActiveCurrency => $warnNoActiveCurrency,
542 warnNoTemplateCaching => ( C4::Context->config('template_cache_dir') ? 0 : 1 ),
543 xml_config_warnings => \@xml_config_warnings,
544 warnStatisticsFieldsError => $warnStatisticsFieldsError,
549 my $perl_modules = C4::Installer::PerlModules->new;
550 $perl_modules->versions_info;
552 my @pm_types = qw(missing_pm upgrade_pm current_pm);
554 foreach my $pm_type(@pm_types) {
555 my $modules = $perl_modules->get_attr($pm_type);
556 foreach (@$modules) {
557 my ($module, $stats) = each %$_;
562 version => $stats->{'cur_ver'},
563 missing => ($pm_type eq 'missing_pm' ? 1 : 0),
564 upgrade => ($pm_type eq 'upgrade_pm' ? 1 : 0),
565 current => ($pm_type eq 'current_pm' ? 1 : 0),
566 require => $stats->{'required'},
567 reqversion => $stats->{'min_ver'},
568 maxversion => $stats->{'max_ver'},
569 excversion => $stats->{'exc_ver'}
575 @components = sort {$a->{'name'} cmp $b->{'name'}} @components;
580 foreach (@components) {
582 unless (++$counter % 4) {
583 push (@$table, {row => $row});
587 # Processing the last line (if there are any modules left)
588 if (scalar(@$row) > 0) {
589 # Extending $row to the table size
591 # Pushing the last line
592 push (@$table, {row => $row});
596 $template->param( table => $table );
599 ## ------------------------------------------
600 ## Koha contributions
602 if ( defined C4::Context->config('docdir') ) {
603 $docdir = C4::Context->config('docdir');
605 # if no <docdir> is defined in koha-conf.xml, use the default location
606 # this is a work-around to stop breakage on upgraded Kohas, bug 8911
607 $docdir = C4::Context->config('intranetdir') . '/docs';
612 -e "$docdir" . "/teams.yaml"
613 ? LoadFile( "$docdir" . "/teams.yaml" )
615 my $dev_team = (sort {$b <=> $a} (keys %{$teams->{team}}))[0];
616 my $short_version = substr($versions{'kohaVersion'},0,5);
617 my $minor = substr($versions{'kohaVersion'},3,2);
618 my $development_version = ( $minor eq '05' || $minor eq '11' ) ? 0 : 1;
619 $template->param( short_version => $short_version );
620 $template->param( development_version => $development_version );
624 -e "$docdir" . "/contributors.yaml"
625 ? LoadFile( "$docdir" . "/contributors.yaml" )
627 for my $version ( sort { $a <=> $b } keys %{$teams->{team}} ) {
628 for my $role ( keys %{ $teams->{team}->{$version} } ) {
629 my $normalized_role = "$role";
630 $normalized_role =~ s/s$//;
631 if ( ref( $teams->{team}->{$version}->{$role} ) eq 'ARRAY' ) {
632 for my $contributor ( @{ $teams->{team}->{$version}->{$role} } ) {
633 my $name = $contributor->{name};
634 # Add role to contributors
635 push @{ $contributors->{$name}->{roles}->{$normalized_role} },
637 # Add openhub to teams
638 if ( exists( $contributors->{$name}->{openhub} ) ) {
639 $contributor->{openhub} = $contributors->{$name}->{openhub};
643 elsif ( $role ne 'release_date' ) {
644 my $name = $teams->{team}->{$version}->{$role}->{name};
645 # Add role to contributors
646 push @{ $contributors->{$name}->{roles}->{$normalized_role} },
648 # Add openhub to teams
649 if ( exists( $contributors->{$name}->{openhub} ) ) {
650 $teams->{team}->{$version}->{$role}->{openhub} =
651 $contributors->{$name}->{openhub};
655 $teams->{team}->{$version}->{$role} = DateTime->from_epoch( epoch => $teams->{team}->{$version}->{$role});
660 ## Create last name ordered array of people from contributors
662 { name => $_, ( $contributors->{$_} ? %{ $contributors->{$_} } : () ) }
664 my ($alast) = ( split( /\s/, $a ) )[-1];
665 my ($blast) = ( split( /\s/, $b ) )[-1];
666 lc($alast) cmp lc($blast)
667 } keys %{$contributors};
669 $template->param( contributors => \@people );
670 $template->param( maintenance_team => $teams->{team}->{$dev_team} );
671 $template->param( release_team => $teams->{team}->{$short_version} );
674 if ( open( my $file, "<:encoding(UTF-8)", "$docdir" . "/history.txt" ) ) {
684 shift @lines; #remove header row
687 my ( $epoch, $date, $desc, $tag ) = split(/\t/);
688 if(!$desc && $date=~ /(?<=\d{4})\s+/) {
689 ($date, $desc)= ($`, $');
701 #foreach my $row2 (@rows2) {
704 push( @$table2, { row2 => $row2 } );
708 $template->param( table2 => $table2 );
710 $template->param( timeline_read_error => 1 );
713 output_html_with_http_headers $query, $cookie, $template->output;