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