Bug 28591: Don't pass debug to get_template_and_user
[koha.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 Modern::Perl;
24
25 use CGI qw ( -utf8 );
26 use DateTime::TimeZone;
27 use File::Spec;
28 use File::Slurp;
29 use List::MoreUtils qw/ any /;
30 use LWP::Simple;
31 use Module::Load::Conditional qw(can_load);
32 use XML::Simple;
33 use Config;
34 use Search::Elasticsearch;
35 use Try::Tiny;
36 use YAML::XS;
37 use Encode;
38
39 use C4::Output;
40 use C4::Auth;
41 use C4::Context;
42 use C4::Installer::PerlModules;
43
44 use Koha;
45 use Koha::DateUtils qw(dt_from_string output_pref);
46 use Koha::Acquisition::Currencies;
47 use Koha::BackgroundJob;
48 use Koha::BiblioFrameworks;
49 use Koha::Email;
50 use Koha::Patron::Categories;
51 use Koha::Patrons;
52 use Koha::Caches;
53 use Koha::Config::SysPrefs;
54 use Koha::Illrequest::Config;
55 use Koha::SearchEngine::Elasticsearch;
56 use Koha::Logger;
57 use Koha::Filter::MARC::ViewPolicy;
58
59 use C4::Members::Statistics;
60
61
62 #use Smart::Comments '####';
63
64 my $query = CGI->new;
65 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
66     {
67         template_name   => "about.tt",
68         query           => $query,
69         type            => "intranet",
70         flagsrequired   => { catalogue => 1 },
71     }
72 );
73
74 my $config_timezone = C4::Context->config('timezone') // '';
75 my $config_invalid  = !DateTime::TimeZone->is_valid_name( $config_timezone );
76 my $env_timezone    = $ENV{TZ} // '';
77 my $env_invalid     = !DateTime::TimeZone->is_valid_name( $env_timezone );
78 my $actual_bad_tz_fallback = 0;
79
80 if ( $config_timezone ne '' &&
81      $config_invalid ) {
82     # Bad config
83     $actual_bad_tz_fallback = 1;
84 }
85 elsif ( $config_timezone eq '' &&
86         $env_timezone    ne '' &&
87         $env_invalid ) {
88     # No config, but bad ENV{TZ}
89     $actual_bad_tz_fallback = 1;
90 }
91
92 my $time_zone = {
93     actual                 => C4::Context->tz->name,
94     actual_bad_tz_fallback => $actual_bad_tz_fallback,
95     config                 => $config_timezone,
96     config_invalid         => $config_invalid,
97     environment            => $env_timezone,
98     environment_invalid    => $env_invalid
99 };
100
101 { # Logger checks
102     my $log4perl_config = C4::Context->config("log4perl_conf");
103     my @log4perl_errors;
104     if ( ! $log4perl_config ) {
105         push @log4perl_errors, 'missing_config_entry'
106     }
107     else {
108         my @lines = read_file($log4perl_config) or push @log4perl_errors, 'cannot_read_config_file';
109         for my $line ( @lines ) {
110             next unless $line =~ m|log4perl.appender.\w+.filename=(.*)|;
111             push @log4perl_errors, 'logfile_not_writable' unless -w $1;
112         }
113     }
114     eval {Koha::Logger->get};
115     push @log4perl_errors, 'cannot_init_module' and warn $@ if $@;
116     $template->param( log4perl_errors => @log4perl_errors );
117 }
118
119 $template->param(
120     time_zone              => $time_zone,
121     current_date_and_time  => output_pref({ dt => dt_from_string(), dateformat => 'iso' })
122 );
123
124 my $perl_path = $^X;
125 if ($^O ne 'VMS') {
126     $perl_path .= $Config{_exe} unless $perl_path =~ m/$Config{_exe}$/i;
127 }
128
129 my $zebraVersion = `zebraidx -V`;
130
131 # Check running PSGI env
132 if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) {
133     $template->param(
134         is_psgi => 1,
135         psgi_server => ($ENV{ PLACK_ENV }) ? "Plack ($ENV{PLACK_ENV})" :
136                        ($ENV{ MOD_PERL })  ? "mod_perl ($ENV{MOD_PERL})" :
137                                              'Unknown'
138     );
139 }
140
141 # Memcached configuration
142 my $memcached_servers   = $ENV{MEMCACHED_SERVERS} || C4::Context->config('memcached_servers');
143 my $memcached_namespace = $ENV{MEMCACHED_NAMESPACE} || C4::Context->config('memcached_namespace') // 'koha';
144
145 my $cache = Koha::Caches->get_instance;
146 my $effective_caching_method = ref($cache->cache);
147 # Memcached may have been running when plack has been initialized but could have been stopped since
148 # FIXME What are the consequences of that??
149 my $is_memcached_still_active = $cache->set_in_cache('test_for_about_page', "just a simple value");
150
151 my $where_is_memcached_config = 'nowhere';
152 if ( $ENV{MEMCACHED_SERVERS} and C4::Context->config('memcached_servers') ) {
153     $where_is_memcached_config = 'both';
154 } elsif ( $ENV{MEMCACHED_SERVERS} and not C4::Context->config('memcached_servers') ) {
155     $where_is_memcached_config = 'ENV_only';
156 } elsif ( C4::Context->config('memcached_servers') ) {
157     $where_is_memcached_config = 'config_only';
158 }
159
160 $template->param(
161     effective_caching_method => $effective_caching_method,
162     memcached_servers   => $memcached_servers,
163     memcached_namespace => $memcached_namespace,
164     is_memcached_still_active => $is_memcached_still_active,
165     where_is_memcached_config => $where_is_memcached_config,
166     memcached_running   => Koha::Caches->get_instance->memcached_cache,
167 );
168
169 # Additional system information for warnings
170
171 my $warnStatisticsFieldsError;
172 my $prefStatisticsFields = C4::Context->preference('StatisticsFields');
173 if ($prefStatisticsFields) {
174     $warnStatisticsFieldsError = $prefStatisticsFields
175         unless ( $prefStatisticsFields eq C4::Members::Statistics->get_fields() );
176 }
177
178 my $prefAutoCreateAuthorities = C4::Context->preference('AutoCreateAuthorities');
179 my $prefBiblioAddsAuthorities = C4::Context->preference('BiblioAddsAuthorities');
180 my $warnPrefBiblioAddsAuthorities = ( $prefAutoCreateAuthorities && ( !$prefBiblioAddsAuthorities) );
181
182 my $prefEasyAnalyticalRecords  = C4::Context->preference('EasyAnalyticalRecords');
183 my $prefUseControlNumber  = C4::Context->preference('UseControlNumber');
184 my $warnPrefEasyAnalyticalRecords  = ( $prefEasyAnalyticalRecords  && $prefUseControlNumber );
185
186 my $AnonymousPatron = C4::Context->preference('AnonymousPatron');
187 my $warnPrefAnonymousPatronOPACPrivacy = (
188     C4::Context->preference('OPACPrivacy')
189         and not $AnonymousPatron
190 );
191 my $warnPrefAnonymousPatronAnonSuggestions = (
192     C4::Context->preference('AnonSuggestions')
193         and not $AnonymousPatron
194 );
195
196 my $anonymous_patron = Koha::Patrons->find( $AnonymousPatron );
197 my $warnPrefAnonymousPatronAnonSuggestions_PatronDoesNotExist = ( $AnonymousPatron && C4::Context->preference('AnonSuggestions') && not $anonymous_patron );
198
199 my $warnPrefAnonymousPatronOPACPrivacy_PatronDoesNotExist = ( not $anonymous_patron and Koha::Patrons->search({ privacy => 2 })->count );
200
201 my $warnPrefKohaAdminEmailAddress = not Email::Valid->address(C4::Context->preference('KohaAdminEmailAddress'));
202
203 my $c = Koha::Items->filter_by_visible_in_opac->count;
204 my @warnings = C4::Context->dbh->selectrow_array('SHOW WARNINGS');
205 my $warnPrefOpacHiddenItems = $warnings[2];
206
207 my $invalid_yesno = Koha::Config::SysPrefs->search(
208     {
209         type  => 'YesNo',
210         value => { -or => { 'is' => undef, -not_in => [ "1", "0" ] } }
211     }
212 );
213 $template->param( invalid_yesno => $invalid_yesno );
214
215 my $errZebraConnection = C4::Context->Zconn("biblioserver",0)->errcode();
216
217 my $warnIsRootUser   = (! $loggedinuser);
218
219 my $warnNoActiveCurrency = (! defined Koha::Acquisition::Currencies->get_active);
220
221 my @xml_config_warnings;
222
223 if (    C4::Context->config('zebra_bib_index_mode')
224     and C4::Context->config('zebra_bib_index_mode') eq 'grs1' )
225 {
226     push @xml_config_warnings, { error => 'zebra_bib_index_mode_is_grs1' };
227 }
228
229 if (    C4::Context->config('zebra_auth_index_mode')
230     and C4::Context->config('zebra_auth_index_mode') eq 'grs1' )
231 {
232     push @xml_config_warnings, { error => 'zebra_auth_index_mode_is_grs1' };
233 }
234
235 my $authorityserver = C4::Context->zebraconfig('authorityserver');
236 if( (   C4::Context->config('zebra_auth_index_mode')
237     and C4::Context->config('zebra_auth_index_mode') eq 'dom' )
238     && ( $authorityserver->{config} !~ /zebra-authorities-dom.cfg/ ) )
239 {
240     push @xml_config_warnings, {
241         error => 'zebra_auth_index_mode_mismatch_warn'
242     };
243 }
244
245 if ( ! defined C4::Context->config('log4perl_conf') ) {
246     push @xml_config_warnings, {
247         error => 'log4perl_entry_missing'
248     }
249 }
250
251 if ( ! defined C4::Context->config('lockdir') ) {
252     push @xml_config_warnings, {
253         error => 'lockdir_entry_missing'
254     }
255 }
256 else {
257     unless ( -w C4::Context->config('lockdir') ) {
258         push @xml_config_warnings, {
259             error   => 'lockdir_not_writable',
260             lockdir => C4::Context->config('lockdir')
261         }
262     }
263 }
264
265 if ( ! defined C4::Context->config('upload_path') ) {
266     if ( Koha::Config::SysPrefs->find('OPACBaseURL')->value ) {
267         # OPACBaseURL seems to be set
268         push @xml_config_warnings, {
269             error => 'uploadpath_entry_missing'
270         }
271     } else {
272         push @xml_config_warnings, {
273             error => 'uploadpath_and_opacbaseurl_entry_missing'
274         }
275     }
276 }
277
278 if ( ! C4::Context->config('tmp_path') ) {
279     my $temporary_directory = C4::Context::temporary_directory;
280     push @xml_config_warnings, {
281         error             => 'tmp_path_missing',
282         effective_tmp_dir => $temporary_directory,
283     }
284 }
285
286 # Test Zebra facets configuration
287 if ( !defined C4::Context->config('use_zebra_facets') ) {
288     push @xml_config_warnings, { error => 'use_zebra_facets_entry_missing' };
289 }
290
291 # ILL module checks
292 if ( C4::Context->preference('ILLModule') ) {
293     my $warnILLConfiguration = 0;
294     my $ill_config_from_file = C4::Context->config("interlibrary_loans");
295     my $ill_config = Koha::Illrequest::Config->new;
296
297     my $available_ill_backends =
298       ( scalar @{ $ill_config->available_backends } > 0 );
299
300     # Check backends
301     if ( !$available_ill_backends ) {
302         $template->param( no_ill_backends => 1 );
303         $warnILLConfiguration = 1;
304     }
305
306     # Check partner_code
307     if ( !Koha::Patron::Categories->find($ill_config->partner_code) ) {
308         $template->param( ill_partner_code_doesnt_exist => $ill_config->partner_code );
309         $warnILLConfiguration = 1;
310     }
311
312     if ( !$ill_config_from_file->{partner_code} ) {
313         # partner code not defined
314         $template->param( ill_partner_code_not_defined => 1 );
315         $warnILLConfiguration = 1;
316     }
317
318
319     if ( !$ill_config_from_file->{branch} ) {
320         # branch not defined
321         $template->param( ill_branch_not_defined => 1 );
322         $warnILLConfiguration = 1;
323     }
324
325     $template->param( warnILLConfiguration => $warnILLConfiguration );
326 }
327
328 if ( C4::Context->preference('SearchEngine') eq 'Elasticsearch' ) {
329     # Check ES configuration health and runtime status
330
331     my $es_status;
332     my $es_config_error;
333     my $es_running = 1;
334
335     my $es_conf;
336     try {
337         $es_conf = Koha::SearchEngine::Elasticsearch::_read_configuration();
338     }
339     catch {
340         if ( ref($_) eq 'Koha::Exceptions::Config::MissingEntry' ) {
341             $template->param( elasticsearch_fatal_config_error => $_->message );
342             $es_config_error = 1;
343         }
344     };
345     if ( !$es_config_error ) {
346
347         my $biblios_index_name     = $es_conf->{index_name} . "_" . $Koha::SearchEngine::BIBLIOS_INDEX;
348         my $authorities_index_name = $es_conf->{index_name} . "_" . $Koha::SearchEngine::AUTHORITIES_INDEX;
349
350         my @indexes = ($biblios_index_name, $authorities_index_name);
351         # TODO: When new indexes get added, we could have other ways to
352         #       fetch the list of available indexes (e.g. plugins, etc)
353         $es_status->{nodes} = $es_conf->{nodes};
354         my $es = Search::Elasticsearch->new({ nodes => $es_conf->{nodes} });
355         my $es_status->{version} = $es->info->{version}->{number};
356
357         foreach my $index ( @indexes ) {
358             my $count;
359             try {
360                 $count = $es->indices->stats( index => $index )
361                       ->{_all}{primaries}{docs}{count};
362             }
363             catch {
364                 if ( ref($_) eq 'Search::Elasticsearch::Error::Missing' ) {
365                     push @{ $es_status->{errors} }, "Index not found ($index)";
366                     $count = -1;
367                 }
368                 elsif ( ref($_) eq 'Search::Elasticsearch::Error::NoNodes' ) {
369                     $es_running = 0;
370                 }
371                 else {
372                     # TODO: when time comes, we will cover more use cases
373                     die $_;
374                 }
375             };
376
377             push @{ $es_status->{indexes} },
378               {
379                 index_name => $index,
380                 count      => $count
381               };
382         }
383         $es_status->{running} = $es_running;
384
385         $template->param( elasticsearch_status => $es_status );
386     }
387 }
388
389 if ( C4::Context->preference('RESTOAuth2ClientCredentials') ) {
390     # Do we have the required deps?
391     unless ( can_load( modules => { 'Net::OAuth2::AuthorizationServer' => undef }) ) {
392         $template->param( oauth2_missing_deps => 1 );
393     }
394 }
395
396 # Sco Patron should not contain any other perms than circulate => self_checkout
397 if (  C4::Context->preference('WebBasedSelfCheck')
398       and C4::Context->preference('AutoSelfCheckAllowed')
399 ) {
400     my $userid = C4::Context->preference('AutoSelfCheckID');
401     my $all_permissions = C4::Auth::get_user_subpermissions( $userid );
402     my ( $has_self_checkout_perm, $has_other_permissions );
403     while ( my ( $module, $permissions ) = each %$all_permissions ) {
404         if ( $module eq 'self_check' ) {
405             while ( my ( $permission, $flag ) = each %$permissions ) {
406                 if ( $permission eq 'self_checkout_module' ) {
407                     $has_self_checkout_perm = 1;
408                 } else {
409                     $has_other_permissions = 1;
410                 }
411             }
412         } else {
413             $has_other_permissions = 1;
414         }
415     }
416     $template->param(
417         AutoSelfCheckPatronDoesNotHaveSelfCheckPerm => not ( $has_self_checkout_perm ),
418         AutoSelfCheckPatronHasTooManyPerm => $has_other_permissions,
419     );
420 }
421
422 # Test YAML system preferences
423 # FIXME: This is list of current YAML formatted prefs, should by type of preference
424 my @yaml_prefs = (
425     "UpdateNotForLoanStatusOnCheckin",
426     "OpacHiddenItems",
427     "BibtexExportAdditionalFields",
428     "RisExportAdditionalFields",
429     "UpdateItemWhenLostFromHoldList",
430     "MarcFieldsToOrder",
431     "MarcItemFieldsToOrder",
432     "UpdateitemLocationOnCheckin",
433     "ItemsDeniedRenewal"
434 );
435 my @bad_yaml_prefs;
436 foreach my $syspref (@yaml_prefs) {
437     my $yaml = C4::Context->preference( $syspref );
438     if ( $yaml ) {
439         eval { YAML::XS::Load( Encode::encode_utf8("$yaml\n\n") ); };
440         if ($@) {
441             push @bad_yaml_prefs, $syspref;
442         }
443     }
444 }
445 $template->param( 'bad_yaml_prefs' => \@bad_yaml_prefs ) if @bad_yaml_prefs;
446
447 {
448     my $dbh       = C4::Context->dbh;
449     my $patrons = $dbh->selectall_arrayref(
450         q|select b.borrowernumber from borrowers b join deletedborrowers db on b.borrowernumber=db.borrowernumber|,
451         { Slice => {} }
452     );
453     my $biblios = $dbh->selectall_arrayref(
454         q|select b.biblionumber from biblio b join deletedbiblio db on b.biblionumber=db.biblionumber|,
455         { Slice => {} }
456     );
457     my $items = $dbh->selectall_arrayref(
458         q|select i.itemnumber from items i join deleteditems di on i.itemnumber=di.itemnumber|,
459         { Slice => {} }
460     );
461     my $checkouts = $dbh->selectall_arrayref(
462         q|select i.issue_id from issues i join old_issues oi on i.issue_id=oi.issue_id|,
463         { Slice => {} }
464     );
465     my $holds = $dbh->selectall_arrayref(
466         q|select r.reserve_id from reserves r join old_reserves o on r.reserve_id=o.reserve_id|,
467         { Slice => {} }
468     );
469     if ( @$patrons or @$biblios or @$items or @$checkouts or @$holds ) {
470         $template->param(
471             has_ai_issues => 1,
472             ai_patrons    => $patrons,
473             ai_biblios    => $biblios,
474             ai_items      => $items,
475             ai_checkouts  => $checkouts,
476             ai_holds      => $holds,
477         );
478     }
479 }
480
481 # Circ rule warnings
482 {
483     my $dbh   = C4::Context->dbh;
484     my $units = Koha::CirculationRules->search({ rule_name => 'lengthunit', rule_value => { -not_in => ['days', 'hours'] } });
485
486     if ( $units->count ) {
487         $template->param(
488             warnIssuingRules => 1,
489             ir_units         => $units,
490         );
491     }
492 }
493
494 # Guarantor relationships warnings
495 {
496     my $dbh   = C4::Context->dbh;
497     my ($bad_relationships_count) = $dbh->selectall_arrayref(q{
498         SELECT COUNT(*)
499         FROM (
500             SELECT relationship FROM borrower_relationships WHERE relationship='_bad_data'
501             UNION ALL
502             SELECT relationship FROM borrowers WHERE relationship='_bad_data') a
503     });
504
505     $bad_relationships_count = $bad_relationships_count->[0]->[0];
506
507     my $existing_relationships = $dbh->selectall_arrayref(q{
508           SELECT DISTINCT(relationship)
509           FROM (
510               SELECT relationship FROM borrower_relationships WHERE relationship IS NOT NULL
511               UNION ALL
512               SELECT relationship FROM borrowers WHERE relationship IS NOT NULL) a
513     });
514
515     my %valid_relationships = map { $_ => 1 } split( /,|\|/, C4::Context->preference('borrowerRelationship') );
516     $valid_relationships{ _bad_data } = 1; # we handle this case in another way
517
518     my $wrong_relationships = [ grep { !$valid_relationships{ $_->[0] } } @{$existing_relationships} ];
519     if ( @$wrong_relationships or $bad_relationships_count ) {
520
521         $template->param(
522             warnRelationships => 1,
523         );
524
525         if ( $wrong_relationships ) {
526             $template->param(
527                 wrong_relationships => $wrong_relationships
528             );
529         }
530         if ($bad_relationships_count) {
531             $template->param(
532                 bad_relationships_count => $bad_relationships_count,
533             );
534         }
535     }
536 }
537
538 {
539     # Test 'bcrypt_settings' config for Pseudonymization
540     $template->param( config_bcrypt_settings_no_set => 1 )
541       if C4::Context->preference('Pseudonymization')
542       and not C4::Context->config('bcrypt_settings');
543 }
544
545 {
546     my @frameworkcodes = Koha::BiblioFrameworks->search->get_column('frameworkcode');
547     my @hidden_biblionumbers;
548     push @frameworkcodes, ""; # it's not in the biblio_frameworks table!
549     for my $frameworkcode ( @frameworkcodes ) {
550         my $shouldhidemarc_opac = Koha::Filter::MARC::ViewPolicy->should_hide_marc(
551             {
552                 frameworkcode => $frameworkcode,
553                 interface     => "opac"
554             }
555         );
556         push @hidden_biblionumbers, { frameworkcode => $frameworkcode, interface => 'opac' }
557           if $shouldhidemarc_opac->{biblionumber};
558
559         my $shouldhidemarc_intranet = Koha::Filter::MARC::ViewPolicy->should_hide_marc(
560             {
561                 frameworkcode => $frameworkcode,
562                 interface     => "intranet"
563             }
564         );
565         push @hidden_biblionumbers, { frameworkcode => $frameworkcode, interface => 'intranet' }
566           if $shouldhidemarc_intranet->{biblionumber};
567     }
568     $template->param( warnHiddenBiblionumbers => \@hidden_biblionumbers );
569 }
570
571 {
572     # BackgroundJob - test connection to message broker
573     eval {
574         Koha::BackgroundJob->connect;
575     };
576     if ( $@ ) {
577         warn $@;
578         $template->param( warnConnectBroker => $@ );
579     }
580 }
581
582 my %versions = C4::Context::get_versions();
583
584 $template->param(
585     kohaVersion   => $versions{'kohaVersion'},
586     osVersion     => $versions{'osVersion'},
587     perlPath      => $perl_path,
588     perlVersion   => $versions{'perlVersion'},
589     perlIncPath   => [ map { perlinc => $_ }, @INC ],
590     mysqlVersion  => $versions{'mysqlVersion'},
591     apacheVersion => $versions{'apacheVersion'},
592     zebraVersion  => $zebraVersion,
593     prefBiblioAddsAuthorities => $prefBiblioAddsAuthorities,
594     prefAutoCreateAuthorities => $prefAutoCreateAuthorities,
595     warnPrefBiblioAddsAuthorities => $warnPrefBiblioAddsAuthorities,
596     warnPrefEasyAnalyticalRecords  => $warnPrefEasyAnalyticalRecords,
597     warnPrefAnonymousPatronOPACPrivacy        => $warnPrefAnonymousPatronOPACPrivacy,
598     warnPrefAnonymousPatronAnonSuggestions    => $warnPrefAnonymousPatronAnonSuggestions,
599     warnPrefAnonymousPatronOPACPrivacy_PatronDoesNotExist     => $warnPrefAnonymousPatronOPACPrivacy_PatronDoesNotExist,
600     warnPrefAnonymousPatronAnonSuggestions_PatronDoesNotExist => $warnPrefAnonymousPatronAnonSuggestions_PatronDoesNotExist,
601     warnPrefKohaAdminEmailAddress => $warnPrefKohaAdminEmailAddress,
602     warnPrefOpacHiddenItems => $warnPrefOpacHiddenItems,
603     errZebraConnection => $errZebraConnection,
604     warnIsRootUser => $warnIsRootUser,
605     warnNoActiveCurrency => $warnNoActiveCurrency,
606     warnNoTemplateCaching => ( C4::Context->config('template_cache_dir') ? 0 : 1 ),
607     xml_config_warnings => \@xml_config_warnings,
608     warnStatisticsFieldsError => $warnStatisticsFieldsError,
609 );
610
611 my @components = ();
612
613 my $perl_modules = C4::Installer::PerlModules->new;
614 $perl_modules->versions_info;
615
616 my @pm_types = qw(missing_pm upgrade_pm current_pm);
617
618 foreach my $pm_type(@pm_types) {
619     my $modules = $perl_modules->get_attr($pm_type);
620     foreach (@$modules) {
621         my ($module, $stats) = each %$_;
622         push(
623             @components,
624             {
625                 name    => $module,
626                 version => $stats->{'cur_ver'},
627                 missing => ($pm_type eq 'missing_pm' ? 1 : 0),
628                 upgrade => ($pm_type eq 'upgrade_pm' ? 1 : 0),
629                 current => ($pm_type eq 'current_pm' ? 1 : 0),
630                 require => $stats->{'required'},
631                 reqversion => $stats->{'min_ver'},
632                 maxversion => $stats->{'max_ver'},
633                 excversion => $stats->{'exc_ver'}
634             }
635         );
636     }
637 }
638
639 @components = sort {$a->{'name'} cmp $b->{'name'}} @components;
640
641 my $counter=0;
642 my $row = [];
643 my $table = [];
644 foreach (@components) {
645     push (@$row, $_);
646     unless (++$counter % 4) {
647         push (@$table, {row => $row});
648         $row = [];
649     }
650 }
651 # Processing the last line (if there are any modules left)
652 if (scalar(@$row) > 0) {
653     # Extending $row to the table size
654     $$row[3] = '';
655     # Pushing the last line
656     push (@$table, {row => $row});
657 }
658 ## ## $table
659
660 $template->param( table => $table );
661
662
663 ## ------------------------------------------
664 ## Koha contributions
665 my $docdir;
666 if ( defined C4::Context->config('docdir') ) {
667     $docdir = C4::Context->config('docdir');
668 } else {
669     # if no <docdir> is defined in koha-conf.xml, use the default location
670     # this is a work-around to stop breakage on upgraded Kohas, bug 8911
671     $docdir = C4::Context->config('intranetdir') . '/docs';
672 }
673
674 ## Release teams
675 my $teams =
676   -e "$docdir" . "/teams.yaml"
677   ? YAML::XS::LoadFile( "$docdir" . "/teams.yaml" )
678   : {};
679 my $dev_team = (sort {$b <=> $a} (keys %{$teams->{team}}))[0];
680 my $short_version = substr($versions{'kohaVersion'},0,5);
681 my $minor = substr($versions{'kohaVersion'},3,2);
682 my $development_version = ( $minor eq '05' || $minor eq '11' ) ? 0 : 1;
683 $template->param( short_version => $short_version );
684 $template->param( development_version => $development_version );
685
686 ## Contributors
687 my $contributors =
688   -e "$docdir" . "/contributors.yaml"
689   ? YAML::XS::LoadFile( "$docdir" . "/contributors.yaml" )
690   : {};
691 delete $contributors->{_others_};
692 for my $version ( sort { $a <=> $b } keys %{$teams->{team}} ) {
693     for my $role ( keys %{ $teams->{team}->{$version} } ) {
694         my $normalized_role = "$role";
695         $normalized_role =~ s/s$//;
696         if ( ref( $teams->{team}->{$version}->{$role} ) eq 'ARRAY' ) {
697             for my $contributor ( @{ $teams->{team}->{$version}->{$role} } ) {
698                 my $name = $contributor->{name};
699                 # Add role to contributors
700                 push @{ $contributors->{$name}->{roles}->{$normalized_role} },
701                   $version;
702                 # Add openhub to teams
703                 if ( exists( $contributors->{$name}->{openhub} ) ) {
704                     $contributor->{openhub} = $contributors->{$name}->{openhub};
705                 }
706             }
707         }
708         elsif ( $role ne 'release_date' ) {
709             my $name = $teams->{team}->{$version}->{$role}->{name};
710             # Add role to contributors
711             push @{ $contributors->{$name}->{roles}->{$normalized_role} },
712               $version;
713             # Add openhub to teams
714             if ( exists( $contributors->{$name}->{openhub} ) ) {
715                 $teams->{team}->{$version}->{$role}->{openhub} =
716                   $contributors->{$name}->{openhub};
717             }
718         }
719         else {
720             $teams->{team}->{$version}->{$role} = DateTime->from_epoch( epoch => $teams->{team}->{$version}->{$role});
721         }
722     }
723 }
724
725 ## Create last name ordered array of people from contributors
726 my @people = map {
727     { name => $_, ( $contributors->{$_} ? %{ $contributors->{$_} } : () ) }
728 } sort {
729   my ($alast) = $a =~ /(\S+)$/;
730   my ($blast) = $b =~ /(\S+)$/;
731   my $cmp = lc($alast||"") cmp lc($blast||"");
732   return $cmp if $cmp;
733
734   my ($a2last) = $a =~ /(\S+)\s\S+$/;
735   my ($b2last) = $b =~ /(\S+)\s\S+$/;
736   lc($a2last||"") cmp lc($b2last||"");
737 } keys %$contributors;
738
739 $template->param( contributors => \@people );
740 $template->param( maintenance_team => $teams->{team}->{$dev_team} );
741 $template->param( release_team => $teams->{team}->{$short_version} );
742
743 ## Timeline
744 if ( open( my $file, "<:encoding(UTF-8)", "$docdir" . "/history.txt" ) ) {
745
746     my $i = 0;
747
748     my @rows2 = ();
749     my $row2  = [];
750
751     my @lines = <$file>;
752     close($file);
753
754     shift @lines; #remove header row
755
756     foreach (@lines) {
757         my ( $epoch, $date, $desc, $tag ) = split(/\t/);
758         if(!$desc && $date=~ /(?<=\d{4})\s+/) {
759             ($date, $desc)= ($`, $');
760         }
761         push(
762             @rows2,
763             {
764                 date => $date,
765                 desc => $desc,
766             }
767         );
768     }
769
770     my $table2 = [];
771     #foreach my $row2 (@rows2) {
772     foreach  (@rows2) {
773         push (@$row2, $_);
774         push( @$table2, { row2 => $row2 } );
775         $row2 = [];
776     }
777
778     $template->param( table2 => $table2 );
779 } else {
780     $template->param( timeline_read_error => 1 );
781 }
782
783 output_html_with_http_headers $query, $cookie, $template->output;