Bug 25506: Fix for "Use of uninitialized value" in about.pl
[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         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')
221     and C4::Context->config('zebra_auth_index_mode') eq 'dom' )
222     && ( $context->{'server'}->{'authorityserver'}->{'config'} !~ /zebra-authorities-dom.cfg/ ) )
223 {
224     push @xml_config_warnings, {
225         error => 'zebra_auth_index_mode_mismatch_warn'
226     };
227 }
228
229 if ( ! defined C4::Context->config('log4perl_conf') ) {
230     push @xml_config_warnings, {
231         error => 'log4perl_entry_missing'
232     }
233 }
234
235 if ( ! defined C4::Context->config('lockdir') ) {
236     push @xml_config_warnings, {
237         error => 'lockdir_entry_missing'
238     }
239 }
240 else {
241     unless ( -w C4::Context->config('lockdir') ) {
242         push @xml_config_warnings, {
243             error   => 'lockdir_not_writable',
244             lockdir => C4::Context->config('lockdir')
245         }
246     }
247 }
248
249 if ( ! defined C4::Context->config('upload_path') ) {
250     if ( Koha::Config::SysPrefs->find('OPACBaseURL')->value ) {
251         # OPACBaseURL seems to be set
252         push @xml_config_warnings, {
253             error => 'uploadpath_entry_missing'
254         }
255     } else {
256         push @xml_config_warnings, {
257             error => 'uploadpath_and_opacbaseurl_entry_missing'
258         }
259     }
260 }
261
262 if ( ! C4::Context->config('tmp_path') ) {
263     my $temporary_directory = C4::Context::temporary_directory;
264     push @xml_config_warnings, {
265         error             => 'tmp_path_missing',
266         effective_tmp_dir => $temporary_directory,
267     }
268 }
269
270 # Test Zebra facets configuration
271 if ( !defined C4::Context->config('use_zebra_facets') ) {
272     push @xml_config_warnings, { error => 'use_zebra_facets_entry_missing' };
273 }
274
275 # ILL module checks
276 if ( C4::Context->preference('ILLModule') ) {
277     my $warnILLConfiguration = 0;
278     my $ill_config_from_file = C4::Context->config("interlibrary_loans");
279     my $ill_config = Koha::Illrequest::Config->new;
280
281     my $available_ill_backends =
282       ( scalar @{ $ill_config->available_backends } > 0 );
283
284     # Check backends
285     if ( !$available_ill_backends ) {
286         $template->param( no_ill_backends => 1 );
287         $warnILLConfiguration = 1;
288     }
289
290     # Check partner_code
291     if ( !Koha::Patron::Categories->find($ill_config->partner_code) ) {
292         $template->param( ill_partner_code_doesnt_exist => $ill_config->partner_code );
293         $warnILLConfiguration = 1;
294     }
295
296     if ( !$ill_config_from_file->{partner_code} ) {
297         # partner code not defined
298         $template->param( ill_partner_code_not_defined => 1 );
299         $warnILLConfiguration = 1;
300     }
301
302
303     if ( !$ill_config_from_file->{branch} ) {
304         # branch not defined
305         $template->param( ill_branch_not_defined => 1 );
306         $warnILLConfiguration = 1;
307     }
308
309     $template->param( warnILLConfiguration => $warnILLConfiguration );
310 }
311
312 if ( C4::Context->preference('SearchEngine') eq 'Elasticsearch' ) {
313     # Check ES configuration health and runtime status
314
315     my $es_status;
316     my $es_config_error;
317     my $es_running = 1;
318
319     my $es_conf;
320     try {
321         $es_conf = Koha::SearchEngine::Elasticsearch::_read_configuration();
322     }
323     catch {
324         if ( ref($_) eq 'Koha::Exceptions::Config::MissingEntry' ) {
325             $template->param( elasticsearch_fatal_config_error => $_->message );
326             $es_config_error = 1;
327         }
328     };
329     if ( !$es_config_error ) {
330
331         my $biblios_index_name     = $es_conf->{index_name} . "_" . $Koha::SearchEngine::BIBLIOS_INDEX;
332         my $authorities_index_name = $es_conf->{index_name} . "_" . $Koha::SearchEngine::AUTHORITIES_INDEX;
333
334         my @indexes = ($biblios_index_name, $authorities_index_name);
335         # TODO: When new indexes get added, we could have other ways to
336         #       fetch the list of available indexes (e.g. plugins, etc)
337         $es_status->{nodes} = $es_conf->{nodes};
338         my $es = Search::Elasticsearch->new({ nodes => $es_conf->{nodes} });
339
340         foreach my $index ( @indexes ) {
341             my $count;
342             try {
343                 $count = $es->indices->stats( index => $index )
344                       ->{_all}{primaries}{docs}{count};
345             }
346             catch {
347                 if ( ref($_) eq 'Search::Elasticsearch::Error::Missing' ) {
348                     push @{ $es_status->{errors} }, "Index not found ($index)";
349                     $count = -1;
350                 }
351                 elsif ( ref($_) eq 'Search::Elasticsearch::Error::NoNodes' ) {
352                     $es_running = 0;
353                 }
354                 else {
355                     # TODO: when time comes, we will cover more use cases
356                     die $_;
357                 }
358             };
359
360             push @{ $es_status->{indexes} },
361               {
362                 index_name => $index,
363                 count      => $count
364               };
365         }
366         $es_status->{running} = $es_running;
367
368         $template->param( elasticsearch_status => $es_status );
369     }
370 }
371
372 if ( C4::Context->preference('RESTOAuth2ClientCredentials') ) {
373     # Do we have the required deps?
374     unless ( can_load( modules => { 'Net::OAuth2::AuthorizationServer' => undef }) ) {
375         $template->param( oauth2_missing_deps => 1 );
376     }
377 }
378
379 # Sco Patron should not contain any other perms than circulate => self_checkout
380 if (  C4::Context->preference('WebBasedSelfCheck')
381       and C4::Context->preference('AutoSelfCheckAllowed')
382 ) {
383     my $userid = C4::Context->preference('AutoSelfCheckID');
384     my $all_permissions = C4::Auth::get_user_subpermissions( $userid );
385     my ( $has_self_checkout_perm, $has_other_permissions );
386     while ( my ( $module, $permissions ) = each %$all_permissions ) {
387         if ( $module eq 'self_check' ) {
388             while ( my ( $permission, $flag ) = each %$permissions ) {
389                 if ( $permission eq 'self_checkout_module' ) {
390                     $has_self_checkout_perm = 1;
391                 } else {
392                     $has_other_permissions = 1;
393                 }
394             }
395         } else {
396             $has_other_permissions = 1;
397         }
398     }
399     $template->param(
400         AutoSelfCheckPatronDoesNotHaveSelfCheckPerm => not ( $has_self_checkout_perm ),
401         AutoSelfCheckPatronHasTooManyPerm => $has_other_permissions,
402     );
403 }
404
405 # Test YAML system preferences
406 # FIXME: This is list of current YAML formatted prefs, should by type of preference
407 my @yaml_prefs = (
408     "UpdateNotForLoanStatusOnCheckin",
409     "OpacHiddenItems",
410     "BibtexExportAdditionalFields",
411     "RisExportAdditionalFields",
412     "UpdateItemWhenLostFromHoldList",
413     "MarcFieldsToOrder",
414     "MarcItemFieldsToOrder",
415     "UpdateitemLocationOnCheckin",
416     "ItemsDeniedRenewal"
417 );
418 my @bad_yaml_prefs;
419 foreach my $syspref (@yaml_prefs) {
420     my $yaml = C4::Context->preference( $syspref );
421     if ( $yaml ) {
422         eval { YAML::Load( "$yaml\n\n" ); };
423         if ($@) {
424             push @bad_yaml_prefs, $syspref;
425         }
426     }
427 }
428 $template->param( 'bad_yaml_prefs' => \@bad_yaml_prefs ) if @bad_yaml_prefs;
429
430 {
431     my $dbh       = C4::Context->dbh;
432     my $patrons = $dbh->selectall_arrayref(
433         q|select b.borrowernumber from borrowers b join deletedborrowers db on b.borrowernumber=db.borrowernumber|,
434         { Slice => {} }
435     );
436     my $biblios = $dbh->selectall_arrayref(
437         q|select b.biblionumber from biblio b join deletedbiblio db on b.biblionumber=db.biblionumber|,
438         { Slice => {} }
439     );
440     my $items = $dbh->selectall_arrayref(
441         q|select i.itemnumber from items i join deleteditems di on i.itemnumber=di.itemnumber|,
442         { Slice => {} }
443     );
444     my $checkouts = $dbh->selectall_arrayref(
445         q|select i.issue_id from issues i join old_issues oi on i.issue_id=oi.issue_id|,
446         { Slice => {} }
447     );
448     my $holds = $dbh->selectall_arrayref(
449         q|select r.reserve_id from reserves r join old_reserves o on r.reserve_id=o.reserve_id|,
450         { Slice => {} }
451     );
452     if ( @$patrons or @$biblios or @$items or @$checkouts or @$holds ) {
453         $template->param(
454             has_ai_issues => 1,
455             ai_patrons    => $patrons,
456             ai_biblios    => $biblios,
457             ai_items      => $items,
458             ai_checkouts  => $checkouts,
459             ai_holds      => $holds,
460         );
461     }
462 }
463
464 # Circ rule warnings
465 {
466     my $dbh   = C4::Context->dbh;
467     my $units = Koha::CirculationRules->search({ rule_name => 'lengthunit', rule_value => { -not_in => ['days', 'hours'] } });
468
469     if ( $units->count ) {
470         $template->param(
471             warnIssuingRules => 1,
472             ir_units         => $units,
473         );
474     }
475 }
476
477 # Guarantor relationships warnings
478 {
479     my $dbh   = C4::Context->dbh;
480     my ($bad_relationships_count) = $dbh->selectall_arrayref(q{
481         SELECT COUNT(*)
482         FROM (
483             SELECT relationship FROM borrower_relationships WHERE relationship='_bad_data'
484             UNION ALL
485             SELECT relationship FROM borrowers WHERE relationship='_bad_data') a
486     });
487
488     $bad_relationships_count = $bad_relationships_count->[0]->[0];
489
490     my $existing_relationships = $dbh->selectall_arrayref(q{
491           SELECT DISTINCT(relationship)
492           FROM (
493               SELECT relationship FROM borrower_relationships WHERE relationship IS NOT NULL
494               UNION ALL
495               SELECT relationship FROM borrowers WHERE relationship IS NOT NULL) a
496     });
497
498     my %valid_relationships = map { $_ => 1 } split( /,|\|/, C4::Context->preference('borrowerRelationship') );
499     $valid_relationships{ _bad_data } = 1; # we handle this case in another way
500
501     my $wrong_relationships = [ grep { !$valid_relationships{ $_->[0] } } @{$existing_relationships} ];
502     if ( @$wrong_relationships or $bad_relationships_count ) {
503
504         $template->param(
505             warnRelationships => 1,
506         );
507
508         if ( $wrong_relationships ) {
509             $template->param(
510                 wrong_relationships => $wrong_relationships
511             );
512         }
513         if ($bad_relationships_count) {
514             $template->param(
515                 bad_relationships_count => $bad_relationships_count,
516             );
517         }
518     }
519 }
520
521 my %versions = C4::Context::get_versions();
522
523 $template->param(
524     kohaVersion   => $versions{'kohaVersion'},
525     osVersion     => $versions{'osVersion'},
526     perlPath      => $perl_path,
527     perlVersion   => $versions{'perlVersion'},
528     perlIncPath   => [ map { perlinc => $_ }, @INC ],
529     mysqlVersion  => $versions{'mysqlVersion'},
530     apacheVersion => $versions{'apacheVersion'},
531     zebraVersion  => $zebraVersion,
532     prefBiblioAddsAuthorities => $prefBiblioAddsAuthorities,
533     prefAutoCreateAuthorities => $prefAutoCreateAuthorities,
534     warnPrefBiblioAddsAuthorities => $warnPrefBiblioAddsAuthorities,
535     warnPrefEasyAnalyticalRecords  => $warnPrefEasyAnalyticalRecords,
536     warnPrefAnonymousPatronOPACPrivacy        => $warnPrefAnonymousPatronOPACPrivacy,
537     warnPrefAnonymousPatronAnonSuggestions    => $warnPrefAnonymousPatronAnonSuggestions,
538     warnPrefAnonymousPatronOPACPrivacy_PatronDoesNotExist     => $warnPrefAnonymousPatronOPACPrivacy_PatronDoesNotExist,
539     warnPrefAnonymousPatronAnonSuggestions_PatronDoesNotExist => $warnPrefAnonymousPatronAnonSuggestions_PatronDoesNotExist,
540     errZebraConnection => $errZebraConnection,
541     warnIsRootUser => $warnIsRootUser,
542     warnNoActiveCurrency => $warnNoActiveCurrency,
543     warnNoTemplateCaching => ( C4::Context->config('template_cache_dir') ? 0 : 1 ),
544     xml_config_warnings => \@xml_config_warnings,
545     warnStatisticsFieldsError => $warnStatisticsFieldsError,
546 );
547
548 my @components = ();
549
550 my $perl_modules = C4::Installer::PerlModules->new;
551 $perl_modules->versions_info;
552
553 my @pm_types = qw(missing_pm upgrade_pm current_pm);
554
555 foreach my $pm_type(@pm_types) {
556     my $modules = $perl_modules->get_attr($pm_type);
557     foreach (@$modules) {
558         my ($module, $stats) = each %$_;
559         push(
560             @components,
561             {
562                 name    => $module,
563                 version => $stats->{'cur_ver'},
564                 missing => ($pm_type eq 'missing_pm' ? 1 : 0),
565                 upgrade => ($pm_type eq 'upgrade_pm' ? 1 : 0),
566                 current => ($pm_type eq 'current_pm' ? 1 : 0),
567                 require => $stats->{'required'},
568                 reqversion => $stats->{'min_ver'},
569                 maxversion => $stats->{'max_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;