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;
28 use List::MoreUtils qw/ any /;
30 use Module::Load::Conditional qw(can_load);
33 use Search::Elasticsearch;
35 use YAML qw/LoadFile/;
43 use Koha::DateUtils qw(dt_from_string output_pref);
44 use Koha::Acquisition::Currencies;
45 use Koha::BiblioFrameworks;
46 use Koha::Patron::Categories;
49 use Koha::Config::SysPrefs;
50 use Koha::Illrequest::Config;
51 use Koha::SearchEngine::Elasticsearch;
52 use Koha::Filter::MARC::ViewPolicy;
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 time_zone => $time_zone,
99 current_date_and_time => output_pref({ dt => dt_from_string(), dateformat => 'iso' })
104 $perl_path .= $Config{_exe} unless $perl_path =~ m/$Config{_exe}$/i;
107 my $zebraVersion = `zebraidx -V`;
109 # Check running PSGI env
110 if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) {
113 psgi_server => ($ENV{ PLACK_ENV }) ? "Plack ($ENV{PLACK_ENV})" :
114 ($ENV{ MOD_PERL }) ? "mod_perl ($ENV{MOD_PERL})" :
119 # Memcached configuration
120 my $memcached_servers = $ENV{MEMCACHED_SERVERS} || C4::Context->config('memcached_servers');
121 my $memcached_namespace = $ENV{MEMCACHED_NAMESPACE} || C4::Context->config('memcached_namespace') // 'koha';
123 my $cache = Koha::Caches->get_instance;
124 my $effective_caching_method = ref($cache->cache);
125 # Memcached may have been running when plack has been initialized but could have been stopped since
126 # FIXME What are the consequences of that??
127 my $is_memcached_still_active = $cache->set_in_cache('test_for_about_page', "just a simple value");
129 my $where_is_memcached_config = 'nowhere';
130 if ( $ENV{MEMCACHED_SERVERS} and C4::Context->config('memcached_servers') ) {
131 $where_is_memcached_config = 'both';
132 } elsif ( $ENV{MEMCACHED_SERVERS} and not C4::Context->config('memcached_servers') ) {
133 $where_is_memcached_config = 'ENV_only';
134 } elsif ( C4::Context->config('memcached_servers') ) {
135 $where_is_memcached_config = 'config_only';
139 effective_caching_method => $effective_caching_method,
140 memcached_servers => $memcached_servers,
141 memcached_namespace => $memcached_namespace,
142 is_memcached_still_active => $is_memcached_still_active,
143 where_is_memcached_config => $where_is_memcached_config,
144 memcached_running => Koha::Caches->get_instance->memcached_cache,
147 # Additional system information for warnings
149 my $warnStatisticsFieldsError;
150 my $prefStatisticsFields = C4::Context->preference('StatisticsFields');
151 if ($prefStatisticsFields) {
152 $warnStatisticsFieldsError = $prefStatisticsFields
153 unless ( $prefStatisticsFields eq C4::Members::Statistics->get_fields() );
156 my $prefAutoCreateAuthorities = C4::Context->preference('AutoCreateAuthorities');
157 my $prefBiblioAddsAuthorities = C4::Context->preference('BiblioAddsAuthorities');
158 my $warnPrefBiblioAddsAuthorities = ( $prefAutoCreateAuthorities && ( !$prefBiblioAddsAuthorities) );
160 my $prefEasyAnalyticalRecords = C4::Context->preference('EasyAnalyticalRecords');
161 my $prefUseControlNumber = C4::Context->preference('UseControlNumber');
162 my $warnPrefEasyAnalyticalRecords = ( $prefEasyAnalyticalRecords && $prefUseControlNumber );
164 my $AnonymousPatron = C4::Context->preference('AnonymousPatron');
165 my $warnPrefAnonymousPatronOPACPrivacy = (
166 C4::Context->preference('OPACPrivacy')
167 and not $AnonymousPatron
169 my $warnPrefAnonymousPatronAnonSuggestions = (
170 C4::Context->preference('AnonSuggestions')
171 and not $AnonymousPatron
174 my $anonymous_patron = Koha::Patrons->find( $AnonymousPatron );
175 my $warnPrefAnonymousPatronAnonSuggestions_PatronDoesNotExist = ( $AnonymousPatron && C4::Context->preference('AnonSuggestions') && not $anonymous_patron );
177 my $warnPrefAnonymousPatronOPACPrivacy_PatronDoesNotExist = ( not $anonymous_patron and Koha::Patrons->search({ privacy => 2 })->count );
179 my $errZebraConnection = C4::Context->Zconn("biblioserver",0)->errcode();
181 my $warnIsRootUser = (! $loggedinuser);
183 my $warnNoActiveCurrency = (! defined Koha::Acquisition::Currencies->get_active);
185 my @xml_config_warnings;
187 my $context = new C4::Context;
189 if ( C4::Context->config('zebra_bib_index_mode')
190 and C4::Context->config('zebra_bib_index_mode') eq 'grs1' )
192 push @xml_config_warnings, { error => 'zebra_bib_index_mode_is_grs1' };
195 if ( C4::Context->config('zebra_auth_index_mode')
196 and C4::Context->config('zebra_auth_index_mode') eq 'grs1' )
198 push @xml_config_warnings, { error => 'zebra_auth_index_mode_is_grs1' };
201 if( ( C4::Context->config('zebra_auth_index_mode')
202 and C4::Context->config('zebra_auth_index_mode') eq 'dom' )
203 && ( $context->{'server'}->{'authorityserver'}->{'config'} !~ /zebra-authorities-dom.cfg/ ) )
205 push @xml_config_warnings, {
206 error => 'zebra_auth_index_mode_mismatch_warn'
210 if ( ! defined C4::Context->config('log4perl_conf') ) {
211 push @xml_config_warnings, {
212 error => 'log4perl_entry_missing'
216 if ( ! defined C4::Context->config('upload_path') ) {
217 if ( Koha::Config::SysPrefs->find('OPACBaseURL')->value ) {
218 # OPACBaseURL seems to be set
219 push @xml_config_warnings, {
220 error => 'uploadpath_entry_missing'
223 push @xml_config_warnings, {
224 error => 'uploadpath_and_opacbaseurl_entry_missing'
229 if ( ! C4::Context->config('tmp_path') ) {
230 my $temporary_directory = C4::Context::temporary_directory;
231 push @xml_config_warnings, {
232 error => 'tmp_path_missing',
233 effective_tmp_dir => $temporary_directory,
237 # Test QueryParser configuration sanity
238 if ( C4::Context->preference( 'UseQueryParser' ) ) {
239 # Get the QueryParser configuration file name
240 my $queryparser_file = C4::Context->config( 'queryparser_config' );
241 my $queryparser_fallback_file = '/etc/koha/searchengine/queryparser.yaml';
242 # Check QueryParser is functional
243 my $QParser = C4::Context->queryparser();
244 my $queryparser_error = {};
245 if ( ! defined $QParser || ref($QParser) ne 'Koha::QueryParser::Driver::PQF' ) {
246 # Error initializing the QueryParser object
247 # Get the used queryparser.yaml file path to report the user
248 $queryparser_error->{ fallback } = ( defined $queryparser_file ) ? 0 : 1;
249 $queryparser_error->{ file } = ( defined $queryparser_file )
251 : $queryparser_fallback_file;
252 # Report error data to the template
253 $template->param( QueryParserError => $queryparser_error );
255 # Check for an absent queryparser_config entry in koha-conf.xml
256 if ( ! defined $queryparser_file ) {
257 # Not an error but a warning for the missing entry in koha-conf-xml
258 push @xml_config_warnings, {
259 error => 'queryparser_entry_missing',
260 file => $queryparser_fallback_file
266 # Test Zebra facets configuration
267 if ( !defined C4::Context->config('use_zebra_facets') ) {
268 push @xml_config_warnings, { error => 'use_zebra_facets_entry_missing' };
272 if ( C4::Context->preference('ILLModule') ) {
273 my $warnILLConfiguration = 0;
274 my $ill_config_from_file = C4::Context->config("interlibrary_loans");
275 my $ill_config = Koha::Illrequest::Config->new;
277 my $available_ill_backends =
278 ( scalar @{ $ill_config->available_backends } > 0 );
281 if ( !$available_ill_backends ) {
282 $template->param( no_ill_backends => 1 );
283 $warnILLConfiguration = 1;
287 if ( !Koha::Patron::Categories->find($ill_config->partner_code) ) {
288 $template->param( ill_partner_code_doesnt_exist => $ill_config->partner_code );
289 $warnILLConfiguration = 1;
292 if ( !$ill_config_from_file->{partner_code} ) {
293 # partner code not defined
294 $template->param( ill_partner_code_not_defined => 1 );
295 $warnILLConfiguration = 1;
299 if ( !$ill_config_from_file->{branch} ) {
301 $template->param( ill_branch_not_defined => 1 );
302 $warnILLConfiguration = 1;
305 $template->param( warnILLConfiguration => $warnILLConfiguration );
308 if ( C4::Context->preference('SearchEngine') eq 'Elasticsearch' ) {
309 # Check ES configuration health and runtime status
317 $es_conf = Koha::SearchEngine::Elasticsearch::_read_configuration();
320 if ( ref($_) eq 'Koha::Exceptions::Config::MissingEntry' ) {
321 $template->param( elasticsearch_fatal_config_error => $_->message );
322 $es_config_error = 1;
325 if ( !$es_config_error ) {
327 my $biblios_index_name = $es_conf->{index_name} . "_" . $Koha::SearchEngine::BIBLIOS_INDEX;
328 my $authorities_index_name = $es_conf->{index_name} . "_" . $Koha::SearchEngine::AUTHORITIES_INDEX;
330 my @indexes = ($biblios_index_name, $authorities_index_name);
331 # TODO: When new indexes get added, we could have other ways to
332 # fetch the list of available indexes (e.g. plugins, etc)
333 $es_status->{nodes} = $es_conf->{nodes};
334 my $es = Search::Elasticsearch->new({ nodes => $es_conf->{nodes} });
335 my $es_status->{version} = $es->info->{version}->{number};
337 foreach my $index ( @indexes ) {
340 $count = $es->indices->stats( index => $index )
341 ->{_all}{primaries}{docs}{count};
344 if ( ref($_) eq 'Search::Elasticsearch::Error::Missing' ) {
345 push @{ $es_status->{errors} }, "Index not found ($index)";
348 elsif ( ref($_) eq 'Search::Elasticsearch::Error::NoNodes' ) {
352 # TODO: when time comes, we will cover more use cases
357 push @{ $es_status->{indexes} },
359 index_name => $index,
363 $es_status->{running} = $es_running;
365 $template->param( elasticsearch_status => $es_status );
369 if ( C4::Context->preference('RESTOAuth2ClientCredentials') ) {
370 # Do we have the required deps?
371 unless ( can_load( modules => { 'Net::OAuth2::AuthorizationServer' => undef }) ) {
372 $template->param( oauth2_missing_deps => 1 );
376 # Sco Patron should not contain any other perms than circulate => self_checkout
377 if ( C4::Context->preference('WebBasedSelfCheck')
378 and C4::Context->preference('AutoSelfCheckAllowed')
380 my $userid = C4::Context->preference('AutoSelfCheckID');
381 my $all_permissions = C4::Auth::get_user_subpermissions( $userid );
382 my ( $has_self_checkout_perm, $has_other_permissions );
383 while ( my ( $module, $permissions ) = each %$all_permissions ) {
384 if ( $module eq 'self_check' ) {
385 while ( my ( $permission, $flag ) = each %$permissions ) {
386 if ( $permission eq 'self_checkout_module' ) {
387 $has_self_checkout_perm = 1;
389 $has_other_permissions = 1;
393 $has_other_permissions = 1;
397 AutoSelfCheckPatronDoesNotHaveSelfCheckPerm => not ( $has_self_checkout_perm ),
398 AutoSelfCheckPatronHasTooManyPerm => $has_other_permissions,
402 # Test YAML system preferences
403 # FIXME: This is list of current YAML formatted prefs, should by type of preference
405 "UpdateNotForLoanStatusOnCheckin",
407 "BibtexExportAdditionalFields",
408 "RisExportAdditionalFields",
409 "UpdateItemWhenLostFromHoldList",
411 "MarcItemFieldsToOrder",
412 "UpdateitemLocationOnCheckin",
416 foreach my $syspref (@yaml_prefs) {
417 my $yaml = C4::Context->preference( $syspref );
419 eval { YAML::Load( "$yaml\n\n" ); };
421 push @bad_yaml_prefs, $syspref;
425 $template->param( 'bad_yaml_prefs' => \@bad_yaml_prefs ) if @bad_yaml_prefs;
428 my $dbh = C4::Context->dbh;
429 my $patrons = $dbh->selectall_arrayref(
430 q|select b.borrowernumber from borrowers b join deletedborrowers db on b.borrowernumber=db.borrowernumber|,
433 my $biblios = $dbh->selectall_arrayref(
434 q|select b.biblionumber from biblio b join deletedbiblio db on b.biblionumber=db.biblionumber|,
437 my $items = $dbh->selectall_arrayref(
438 q|select i.itemnumber from items i join deleteditems di on i.itemnumber=di.itemnumber|,
441 my $checkouts = $dbh->selectall_arrayref(
442 q|select i.issue_id from issues i join old_issues oi on i.issue_id=oi.issue_id|,
445 my $holds = $dbh->selectall_arrayref(
446 q|select r.reserve_id from reserves r join old_reserves o on r.reserve_id=o.reserve_id|,
449 if ( @$patrons or @$biblios or @$items or @$checkouts or @$holds ) {
452 ai_patrons => $patrons,
453 ai_biblios => $biblios,
455 ai_checkouts => $checkouts,
463 my $dbh = C4::Context->dbh;
464 my $units = $dbh->selectall_arrayref(
465 q|SELECT branchcode, categorycode, itemtype, lengthunit FROM issuingrules WHERE lengthunit NOT IN ( 'days', 'hours' ); |,
471 warnIssuingRules => 1,
477 # Guarantor relationships warnings
479 my $dbh = C4::Context->dbh;
480 my ($bad_relationships_count) = $dbh->selectall_arrayref(q{
483 SELECT relationship FROM borrower_relationships WHERE relationship='_bad_data'
485 SELECT relationship FROM borrowers WHERE relationship='_bad_data') a
488 $bad_relationships_count = $bad_relationships_count->[0]->[0];
490 my $existing_relationships = $dbh->selectall_arrayref(q{
491 SELECT DISTINCT(relationship)
493 SELECT relationship FROM borrower_relationships WHERE relationship IS NOT NULL
495 SELECT relationship FROM borrowers WHERE relationship IS NOT NULL) a
498 my %valid_relationships = map { $_ => 1 } split( /,|\|/, C4::Context->preference('borrowerRelationship') );
499 $valid_relationships{ _bad_data } = 1; # we handle this case in another way
501 my $wrong_relationships = [ grep { !$valid_relationships{ $_->[0] } } @{$existing_relationships} ];
502 if ( @$wrong_relationships or $bad_relationships_count ) {
505 warnRelationships => 1,
508 if ( $wrong_relationships ) {
510 wrong_relationships => $wrong_relationships
513 if ($bad_relationships_count) {
515 bad_relationships_count => $bad_relationships_count,
522 my @frameworkcodes = Koha::BiblioFrameworks->search->get_column('frameworkcode');
523 my @hidden_biblionumbers;
524 push @frameworkcodes, ""; # it's not in the biblio_frameworks table!
525 for my $frameworkcode ( @frameworkcodes ) {
526 my $shouldhidemarc_opac = Koha::Filter::MARC::ViewPolicy->should_hide_marc(
528 frameworkcode => $frameworkcode,
532 push @hidden_biblionumbers, { frameworkcode => $frameworkcode, interface => 'opac' }
533 if $shouldhidemarc_opac->{biblionumber};
535 my $shouldhidemarc_intranet = Koha::Filter::MARC::ViewPolicy->should_hide_marc(
537 frameworkcode => $frameworkcode,
538 interface => "intranet"
541 push @hidden_biblionumbers, { frameworkcode => $frameworkcode, interface => 'intranet' }
542 if $shouldhidemarc_intranet->{biblionumber};
544 $template->param( warnHiddenBiblionumbers => \@hidden_biblionumbers );
547 my %versions = C4::Context::get_versions();
550 kohaVersion => $versions{'kohaVersion'},
551 osVersion => $versions{'osVersion'},
552 perlPath => $perl_path,
553 perlVersion => $versions{'perlVersion'},
554 perlIncPath => [ map { perlinc => $_ }, @INC ],
555 mysqlVersion => $versions{'mysqlVersion'},
556 apacheVersion => $versions{'apacheVersion'},
557 zebraVersion => $zebraVersion,
558 prefBiblioAddsAuthorities => $prefBiblioAddsAuthorities,
559 prefAutoCreateAuthorities => $prefAutoCreateAuthorities,
560 warnPrefBiblioAddsAuthorities => $warnPrefBiblioAddsAuthorities,
561 warnPrefEasyAnalyticalRecords => $warnPrefEasyAnalyticalRecords,
562 warnPrefAnonymousPatronOPACPrivacy => $warnPrefAnonymousPatronOPACPrivacy,
563 warnPrefAnonymousPatronAnonSuggestions => $warnPrefAnonymousPatronAnonSuggestions,
564 warnPrefAnonymousPatronOPACPrivacy_PatronDoesNotExist => $warnPrefAnonymousPatronOPACPrivacy_PatronDoesNotExist,
565 warnPrefAnonymousPatronAnonSuggestions_PatronDoesNotExist => $warnPrefAnonymousPatronAnonSuggestions_PatronDoesNotExist,
566 errZebraConnection => $errZebraConnection,
567 warnIsRootUser => $warnIsRootUser,
568 warnNoActiveCurrency => $warnNoActiveCurrency,
569 warnNoTemplateCaching => ( C4::Context->config('template_cache_dir') ? 0 : 1 ),
570 xml_config_warnings => \@xml_config_warnings,
571 warnStatisticsFieldsError => $warnStatisticsFieldsError,
576 my $perl_modules = C4::Installer::PerlModules->new;
577 $perl_modules->versions_info;
579 my @pm_types = qw(missing_pm upgrade_pm current_pm);
581 foreach my $pm_type(@pm_types) {
582 my $modules = $perl_modules->get_attr($pm_type);
583 foreach (@$modules) {
584 my ($module, $stats) = each %$_;
589 version => $stats->{'cur_ver'},
590 missing => ($pm_type eq 'missing_pm' ? 1 : 0),
591 upgrade => ($pm_type eq 'upgrade_pm' ? 1 : 0),
592 current => ($pm_type eq 'current_pm' ? 1 : 0),
593 require => $stats->{'required'},
594 reqversion => $stats->{'min_ver'},
600 @components = sort {$a->{'name'} cmp $b->{'name'}} @components;
605 foreach (@components) {
607 unless (++$counter % 4) {
608 push (@$table, {row => $row});
612 # Processing the last line (if there are any modules left)
613 if (scalar(@$row) > 0) {
614 # Extending $row to the table size
616 # Pushing the last line
617 push (@$table, {row => $row});
621 $template->param( table => $table );
624 ## ------------------------------------------
625 ## Koha contributions
627 if ( defined C4::Context->config('docdir') ) {
628 $docdir = C4::Context->config('docdir');
630 # if no <docdir> is defined in koha-conf.xml, use the default location
631 # this is a work-around to stop breakage on upgraded Kohas, bug 8911
632 $docdir = C4::Context->config('intranetdir') . '/docs';
637 -e "$docdir" . "/teams.yaml"
638 ? LoadFile( "$docdir" . "/teams.yaml" )
640 my $dev_team = (sort {$b <=> $a} (keys %{$teams->{team}}))[0];
641 my $short_version = substr($versions{'kohaVersion'},0,5);
642 my $minor = substr($versions{'kohaVersion'},3,2);
643 my $development_version = ( $minor eq '05' || $minor eq '11' ) ? 0 : 1;
644 $template->param( short_version => $short_version );
645 $template->param( development_version => $development_version );
649 -e "$docdir" . "/contributors.yaml"
650 ? LoadFile( "$docdir" . "/contributors.yaml" )
652 delete $contributors->{_others_};
653 for my $version ( sort { $a <=> $b } keys %{$teams->{team}} ) {
654 for my $role ( keys %{ $teams->{team}->{$version} } ) {
655 my $normalized_role = "$role";
656 $normalized_role =~ s/s$//;
657 if ( ref( $teams->{team}->{$version}->{$role} ) eq 'ARRAY' ) {
658 for my $contributor ( @{ $teams->{team}->{$version}->{$role} } ) {
659 my $name = $contributor->{name};
660 # Add role to contributors
661 push @{ $contributors->{$name}->{roles}->{$normalized_role} },
663 # Add openhub to teams
664 if ( exists( $contributors->{$name}->{openhub} ) ) {
665 $contributor->{openhub} = $contributors->{$name}->{openhub};
669 elsif ( $role ne 'release_date' ) {
670 my $name = $teams->{team}->{$version}->{$role}->{name};
671 # Add role to contributors
672 push @{ $contributors->{$name}->{roles}->{$normalized_role} },
674 # Add openhub to teams
675 if ( exists( $contributors->{$name}->{openhub} ) ) {
676 $teams->{team}->{$version}->{$role}->{openhub} =
677 $contributors->{$name}->{openhub};
681 $teams->{team}->{$version}->{$role} = DateTime->from_epoch( epoch => $teams->{team}->{$version}->{$role});
686 ## Create last name ordered array of people from contributors
688 { name => $_, ( $contributors->{$_} ? %{ $contributors->{$_} } : () ) }
690 my ($alast) = $a =~ /(\S+)$/;
691 my ($blast) = $b =~ /(\S+)$/;
692 my $cmp = lc($alast||"") cmp lc($blast||"");
695 my ($a2last) = $a =~ /(\S+)\s\S+$/;
696 my ($b2last) = $b =~ /(\S+)\s\S+$/;
697 lc($a2last||"") cmp lc($b2last||"");
698 } keys %$contributors;
700 $template->param( contributors => \@people );
701 $template->param( maintenance_team => $teams->{team}->{$dev_team} );
702 $template->param( release_team => $teams->{team}->{$short_version} );
705 if ( open( my $file, "<:encoding(UTF-8)", "$docdir" . "/history.txt" ) ) {
715 shift @lines; #remove header row
718 my ( $epoch, $date, $desc, $tag ) = split(/\t/);
719 if(!$desc && $date=~ /(?<=\d{4})\s+/) {
720 ($date, $desc)= ($`, $');
732 #foreach my $row2 (@rows2) {
735 push( @$table2, { row2 => $row2 } );
739 $template->param( table2 => $table2 );
741 $template->param( timeline_read_error => 1 );
744 output_html_with_http_headers $query, $cookie, $template->output;