Bug 24663: (follow-up) Remove authnotrequired if set to 0
[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 qw/LoadFile/;
37
38 use C4::Output;
39 use C4::Auth;
40 use C4::Context;
41 use C4::Installer::PerlModules;
42
43 use Koha;
44 use Koha::DateUtils qw(dt_from_string output_pref);
45 use Koha::Acquisition::Currencies;
46 use Koha::Patron::Categories;
47 use Koha::Patrons;
48 use Koha::Caches;
49 use Koha::Config::SysPrefs;
50 use Koha::Illrequest::Config;
51 use Koha::SearchEngine::Elasticsearch;
52 use Koha::Logger;
53
54 use C4::Members::Statistics;
55
56
57 #use Smart::Comments '####';
58
59 my $query = new CGI;
60 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
61     {
62         template_name   => "about.tt",
63         query           => $query,
64         type            => "intranet",
65         flagsrequired   => { catalogue => 1 },
66         debug           => 1,
67     }
68 );
69
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;
75
76 if ( $config_timezone ne '' &&
77      $config_invalid ) {
78     # Bad config
79     $actual_bad_tz_fallback = 1;
80 }
81 elsif ( $config_timezone eq '' &&
82         $env_timezone    ne '' &&
83         $env_invalid ) {
84     # No config, but bad ENV{TZ}
85     $actual_bad_tz_fallback = 1;
86 }
87
88 my $time_zone = {
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
95 };
96
97 { # Logger checks
98     my $log4perl_config = C4::Context->config("log4perl_conf");
99     my @log4perl_errors;
100     if ( ! $log4perl_config ) {
101         push @log4perl_errors, 'missing_config_entry'
102     }
103     else {
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;
108         }
109     }
110     eval {Koha::Logger->get};
111     push @log4perl_errors, 'cannot_init_module' and warn $@ if $@;
112     $template->param( log4perl_errors => @log4perl_errors );
113 }
114
115 $template->param(
116     time_zone              => $time_zone,
117     current_date_and_time  => output_pref({ dt => dt_from_string(), dateformat => 'iso' })
118 );
119
120 my $perl_path = $^X;
121 if ($^O ne 'VMS') {
122     $perl_path .= $Config{_exe} unless $perl_path =~ m/$Config{_exe}$/i;
123 }
124
125 my $zebraVersion = `zebraidx -V`;
126
127 # Check running PSGI env
128 if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) {
129     $template->param(
130         is_psgi => 1,
131         psgi_server => ($ENV{ PLACK_ENV }) ? "Plack ($ENV{PLACK_ENV})" :
132                        ($ENV{ MOD_PERL })  ? "mod_perl ($ENV{MOD_PERL})" :
133                                              'Unknown'
134     );
135 }
136
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';
140
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");
146
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';
154 }
155
156 $template->param(
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,
163 );
164
165 # Additional system information for warnings
166
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() );
172 }
173
174 my $prefAutoCreateAuthorities = C4::Context->preference('AutoCreateAuthorities');
175 my $prefBiblioAddsAuthorities = C4::Context->preference('BiblioAddsAuthorities');
176 my $warnPrefBiblioAddsAuthorities = ( $prefAutoCreateAuthorities && ( !$prefBiblioAddsAuthorities) );
177
178 my $prefEasyAnalyticalRecords  = C4::Context->preference('EasyAnalyticalRecords');
179 my $prefUseControlNumber  = C4::Context->preference('UseControlNumber');
180 my $warnPrefEasyAnalyticalRecords  = ( $prefEasyAnalyticalRecords  && $prefUseControlNumber );
181
182 my $AnonymousPatron = C4::Context->preference('AnonymousPatron');
183 my $warnPrefAnonymousPatronOPACPrivacy = (
184     C4::Context->preference('OPACPrivacy')
185         and not $AnonymousPatron
186 );
187 my $warnPrefAnonymousPatronAnonSuggestions = (
188     C4::Context->preference('AnonSuggestions')
189         and not $AnonymousPatron
190 );
191
192 my $anonymous_patron = Koha::Patrons->find( $AnonymousPatron );
193 my $warnPrefAnonymousPatronAnonSuggestions_PatronDoesNotExist = ( $AnonymousPatron && C4::Context->preference('AnonSuggestions') && not $anonymous_patron );
194
195 my $warnPrefAnonymousPatronOPACPrivacy_PatronDoesNotExist = ( not $anonymous_patron and Koha::Patrons->search({ privacy => 2 })->count );
196
197 my $errZebraConnection = C4::Context->Zconn("biblioserver",0)->errcode();
198
199 my $warnIsRootUser   = (! $loggedinuser);
200
201 my $warnNoActiveCurrency = (! defined Koha::Acquisition::Currencies->get_active);
202
203 my @xml_config_warnings;
204
205 my $context = new C4::Context;
206
207 if (    C4::Context->config('zebra_bib_index_mode')
208     and C4::Context->config('zebra_bib_index_mode') eq 'grs1' )
209 {
210     push @xml_config_warnings, { error => 'zebra_bib_index_mode_is_grs1' };
211 }
212
213 if (    C4::Context->config('zebra_auth_index_mode')
214     and C4::Context->config('zebra_auth_index_mode') eq 'grs1' )
215 {
216     push @xml_config_warnings, { error => 'zebra_auth_index_mode_is_grs1' };
217 }
218
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/ ) )
222 {
223     push @xml_config_warnings, {
224         error => 'zebra_auth_index_mode_mismatch_warn'
225     };
226 }
227
228 if ( ! defined C4::Context->config('log4perl_conf') ) {
229     push @xml_config_warnings, {
230         error => 'log4perl_entry_missing'
231     }
232 }
233
234 if ( ! defined C4::Context->config('lockdir') ) {
235     push @xml_config_warnings, {
236         error => 'lockdir_entry_missing'
237     }
238 }
239 else {
240     unless ( -w C4::Context->config('lockdir') ) {
241         push @xml_config_warnings, {
242             error   => 'lockdir_not_writable',
243             lockdir => C4::Context->config('lockdir')
244         }
245     }
246 }
247
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'
253         }
254     } else {
255         push @xml_config_warnings, {
256             error => 'uploadpath_and_opacbaseurl_entry_missing'
257         }
258     }
259 }
260
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,
266     }
267 }
268
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' };
272 }
273
274 # ILL module checks
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;
279
280     my $available_ill_backends =
281       ( scalar @{ $ill_config->available_backends } > 0 );
282
283     # Check backends
284     if ( !$available_ill_backends ) {
285         $template->param( no_ill_backends => 1 );
286         $warnILLConfiguration = 1;
287     }
288
289     # Check partner_code
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;
293     }
294
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;
299     }
300
301
302     if ( !$ill_config_from_file->{branch} ) {
303         # branch not defined
304         $template->param( ill_branch_not_defined => 1 );
305         $warnILLConfiguration = 1;
306     }
307
308     $template->param( warnILLConfiguration => $warnILLConfiguration );
309 }
310
311 if ( C4::Context->preference('SearchEngine') eq 'Elasticsearch' ) {
312     # Check ES configuration health and runtime status
313
314     my $es_status;
315     my $es_config_error;
316     my $es_running = 1;
317
318     my $es_conf;
319     try {
320         $es_conf = Koha::SearchEngine::Elasticsearch::_read_configuration();
321     }
322     catch {
323         if ( ref($_) eq 'Koha::Exceptions::Config::MissingEntry' ) {
324             $template->param( elasticsearch_fatal_config_error => $_->message );
325             $es_config_error = 1;
326         }
327     };
328     if ( !$es_config_error ) {
329
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;
332
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} });
338
339         foreach my $index ( @indexes ) {
340             my $count;
341             try {
342                 $count = $es->indices->stats( index => $index )
343                       ->{_all}{primaries}{docs}{count};
344             }
345             catch {
346                 if ( ref($_) eq 'Search::Elasticsearch::Error::Missing' ) {
347                     push @{ $es_status->{errors} }, "Index not found ($index)";
348                     $count = -1;
349                 }
350                 elsif ( ref($_) eq 'Search::Elasticsearch::Error::NoNodes' ) {
351                     $es_running = 0;
352                 }
353                 else {
354                     # TODO: when time comes, we will cover more use cases
355                     die $_;
356                 }
357             };
358
359             push @{ $es_status->{indexes} },
360               {
361                 index_name => $index,
362                 count      => $count
363               };
364         }
365         $es_status->{running} = $es_running;
366
367         $template->param( elasticsearch_status => $es_status );
368     }
369 }
370
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 );
375     }
376 }
377
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')
381 ) {
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;
390                 } else {
391                     $has_other_permissions = 1;
392                 }
393             }
394         } else {
395             $has_other_permissions = 1;
396         }
397     }
398     $template->param(
399         AutoSelfCheckPatronDoesNotHaveSelfCheckPerm => not ( $has_self_checkout_perm ),
400         AutoSelfCheckPatronHasTooManyPerm => $has_other_permissions,
401     );
402 }
403
404 # Test YAML system preferences
405 # FIXME: This is list of current YAML formatted prefs, should by type of preference
406 my @yaml_prefs = (
407     "UpdateNotForLoanStatusOnCheckin",
408     "OpacHiddenItems",
409     "BibtexExportAdditionalFields",
410     "RisExportAdditionalFields",
411     "UpdateItemWhenLostFromHoldList",
412     "MarcFieldsToOrder",
413     "MarcItemFieldsToOrder",
414     "UpdateitemLocationOnCheckin",
415     "ItemsDeniedRenewal"
416 );
417 my @bad_yaml_prefs;
418 foreach my $syspref (@yaml_prefs) {
419     my $yaml = C4::Context->preference( $syspref );
420     if ( $yaml ) {
421         eval { YAML::Load( "$yaml\n\n" ); };
422         if ($@) {
423             push @bad_yaml_prefs, $syspref;
424         }
425     }
426 }
427 $template->param( 'bad_yaml_prefs' => \@bad_yaml_prefs ) if @bad_yaml_prefs;
428
429 {
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|,
433         { Slice => {} }
434     );
435     my $biblios = $dbh->selectall_arrayref(
436         q|select b.biblionumber from biblio b join deletedbiblio db on b.biblionumber=db.biblionumber|,
437         { Slice => {} }
438     );
439     my $items = $dbh->selectall_arrayref(
440         q|select i.itemnumber from items i join deleteditems di on i.itemnumber=di.itemnumber|,
441         { Slice => {} }
442     );
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|,
445         { Slice => {} }
446     );
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|,
449         { Slice => {} }
450     );
451     if ( @$patrons or @$biblios or @$items or @$checkouts or @$holds ) {
452         $template->param(
453             has_ai_issues => 1,
454             ai_patrons    => $patrons,
455             ai_biblios    => $biblios,
456             ai_items      => $items,
457             ai_checkouts  => $checkouts,
458             ai_holds      => $holds,
459         );
460     }
461 }
462
463 # Circ rule warnings
464 {
465     my $dbh   = C4::Context->dbh;
466     my $units = Koha::CirculationRules->search({ rule_name => 'lengthunit', rule_value => { -not_in => ['days', 'hours'] } });
467
468     if ( $units->count ) {
469         $template->param(
470             warnIssuingRules => 1,
471             ir_units         => $units,
472         );
473     }
474 }
475
476 # Guarantor relationships warnings
477 {
478     my $dbh   = C4::Context->dbh;
479     my ($bad_relationships_count) = $dbh->selectall_arrayref(q{
480         SELECT COUNT(*)
481         FROM (
482             SELECT relationship FROM borrower_relationships WHERE relationship='_bad_data'
483             UNION ALL
484             SELECT relationship FROM borrowers WHERE relationship='_bad_data') a
485     });
486
487     $bad_relationships_count = $bad_relationships_count->[0]->[0];
488
489     my $existing_relationships = $dbh->selectall_arrayref(q{
490           SELECT DISTINCT(relationship)
491           FROM (
492               SELECT relationship FROM borrower_relationships WHERE relationship IS NOT NULL
493               UNION ALL
494               SELECT relationship FROM borrowers WHERE relationship IS NOT NULL) a
495     });
496
497     my %valid_relationships = map { $_ => 1 } split( /,|\|/, C4::Context->preference('borrowerRelationship') );
498     $valid_relationships{ _bad_data } = 1; # we handle this case in another way
499
500     my $wrong_relationships = [ grep { !$valid_relationships{ $_->[0] } } @{$existing_relationships} ];
501     if ( @$wrong_relationships or $bad_relationships_count ) {
502
503         $template->param(
504             warnRelationships => 1,
505         );
506
507         if ( $wrong_relationships ) {
508             $template->param(
509                 wrong_relationships => $wrong_relationships
510             );
511         }
512         if ($bad_relationships_count) {
513             $template->param(
514                 bad_relationships_count => $bad_relationships_count,
515             );
516         }
517     }
518 }
519
520 my %versions = C4::Context::get_versions();
521
522 $template->param(
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,
545 );
546
547 my @components = ();
548
549 my $perl_modules = C4::Installer::PerlModules->new;
550 $perl_modules->versions_info;
551
552 my @pm_types = qw(missing_pm upgrade_pm current_pm);
553
554 foreach my $pm_type(@pm_types) {
555     my $modules = $perl_modules->get_attr($pm_type);
556     foreach (@$modules) {
557         my ($module, $stats) = each %$_;
558         push(
559             @components,
560             {
561                 name    => $module,
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'}
570             }
571         );
572     }
573 }
574
575 @components = sort {$a->{'name'} cmp $b->{'name'}} @components;
576
577 my $counter=0;
578 my $row = [];
579 my $table = [];
580 foreach (@components) {
581     push (@$row, $_);
582     unless (++$counter % 4) {
583         push (@$table, {row => $row});
584         $row = [];
585     }
586 }
587 # Processing the last line (if there are any modules left)
588 if (scalar(@$row) > 0) {
589     # Extending $row to the table size
590     $$row[3] = '';
591     # Pushing the last line
592     push (@$table, {row => $row});
593 }
594 ## ## $table
595
596 $template->param( table => $table );
597
598
599 ## ------------------------------------------
600 ## Koha contributions
601 my $docdir;
602 if ( defined C4::Context->config('docdir') ) {
603     $docdir = C4::Context->config('docdir');
604 } else {
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';
608 }
609
610 ## Release teams
611 my $teams =
612   -e "$docdir" . "/teams.yaml"
613   ? LoadFile( "$docdir" . "/teams.yaml" )
614   : {};
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 );
621
622 ## Contributors
623 my $contributors =
624   -e "$docdir" . "/contributors.yaml"
625   ? LoadFile( "$docdir" . "/contributors.yaml" )
626   : {};
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} },
636                   $version;
637                 # Add openhub to teams
638                 if ( exists( $contributors->{$name}->{openhub} ) ) {
639                     $contributor->{openhub} = $contributors->{$name}->{openhub};
640                 }
641             }
642         }
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} },
647               $version;
648             # Add openhub to teams
649             if ( exists( $contributors->{$name}->{openhub} ) ) {
650                 $teams->{team}->{$version}->{$role}->{openhub} =
651                   $contributors->{$name}->{openhub};
652             }
653         }
654         else {
655             $teams->{team}->{$version}->{$role} = DateTime->from_epoch( epoch => $teams->{team}->{$version}->{$role});
656         }
657     }
658 }
659
660 ## Create last name ordered array of people from contributors
661 my @people = map {
662     { name => $_, ( $contributors->{$_} ? %{ $contributors->{$_} } : () ) }
663 } sort {
664     my ($alast) = ( split( /\s/, $a ) )[-1];
665     my ($blast) = ( split( /\s/, $b ) )[-1];
666     lc($alast) cmp lc($blast)
667 } keys %{$contributors};
668
669 $template->param( contributors => \@people );
670 $template->param( maintenance_team => $teams->{team}->{$dev_team} );
671 $template->param( release_team => $teams->{team}->{$short_version} );
672
673 ## Timeline
674 if ( open( my $file, "<:encoding(UTF-8)", "$docdir" . "/history.txt" ) ) {
675
676     my $i = 0;
677
678     my @rows2 = ();
679     my $row2  = [];
680
681     my @lines = <$file>;
682     close($file);
683
684     shift @lines; #remove header row
685
686     foreach (@lines) {
687         my ( $epoch, $date, $desc, $tag ) = split(/\t/);
688         if(!$desc && $date=~ /(?<=\d{4})\s+/) {
689             ($date, $desc)= ($`, $');
690         }
691         push(
692             @rows2,
693             {
694                 date => $date,
695                 desc => $desc,
696             }
697         );
698     }
699
700     my $table2 = [];
701     #foreach my $row2 (@rows2) {
702     foreach  (@rows2) {
703         push (@$row2, $_);
704         push( @$table2, { row2 => $row2 } );
705         $row2 = [];
706     }
707
708     $template->param( table2 => $table2 );
709 } else {
710     $template->param( timeline_read_error => 1 );
711 }
712
713 output_html_with_http_headers $query, $cookie, $template->output;