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