Bug 24215: Correct display of guarantor relationship errors
[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 my $warnPrefAnonymousPatron = (
163     C4::Context->preference('OPACPrivacy')
164         and not C4::Context->preference('AnonymousPatron')
165 );
166
167 my $anonymous_patron = Koha::Patrons->find( C4::Context->preference('AnonymousPatron') );
168 my $warnPrefAnonymousPatron_PatronDoesNotExist = ( not $anonymous_patron and Koha::Patrons->search({ privacy => 2 })->count );
169
170 my $errZebraConnection = C4::Context->Zconn("biblioserver",0)->errcode();
171
172 my $warnIsRootUser   = (! $loggedinuser);
173
174 my $warnNoActiveCurrency = (! defined Koha::Acquisition::Currencies->get_active);
175
176 my @xml_config_warnings;
177
178 my $context = new C4::Context;
179
180 if (    C4::Context->config('zebra_bib_index_mode')
181     and C4::Context->config('zebra_bib_index_mode') eq 'grs1' )
182 {
183     push @xml_config_warnings, { error => 'zebra_bib_index_mode_is_grs1' };
184 }
185
186 if (    C4::Context->config('zebra_auth_index_mode')
187     and C4::Context->config('zebra_auth_index_mode') eq 'grs1' )
188 {
189     push @xml_config_warnings, { error => 'zebra_auth_index_mode_is_grs1' };
190 }
191
192 if ( (C4::Context->config('zebra_auth_index_mode') eq 'dom') && ($context->{'server'}->{'authorityserver'}->{'config'} !~ /zebra-authorities-dom.cfg/) ) {
193     push @xml_config_warnings, {
194         error => 'zebra_auth_index_mode_mismatch_warn'
195     };
196 }
197
198 if ( ! defined C4::Context->config('log4perl_conf') ) {
199     push @xml_config_warnings, {
200         error => 'log4perl_entry_missing'
201     }
202 }
203
204 if ( ! defined C4::Context->config('upload_path') ) {
205     if ( Koha::Config::SysPrefs->find('OPACBaseURL')->value ) {
206         # OPACBaseURL seems to be set
207         push @xml_config_warnings, {
208             error => 'uploadpath_entry_missing'
209         }
210     } else {
211         push @xml_config_warnings, {
212             error => 'uploadpath_and_opacbaseurl_entry_missing'
213         }
214     }
215 }
216
217 if ( ! C4::Context->config('tmp_path') ) {
218     my $temporary_directory = C4::Context::temporary_directory;
219     push @xml_config_warnings, {
220         error             => 'tmp_path_missing',
221         effective_tmp_dir => $temporary_directory,
222     }
223 }
224
225 # Test QueryParser configuration sanity
226 if ( C4::Context->preference( 'UseQueryParser' ) ) {
227     # Get the QueryParser configuration file name
228     my $queryparser_file          = C4::Context->config( 'queryparser_config' );
229     my $queryparser_fallback_file = '/etc/koha/searchengine/queryparser.yaml';
230     # Check QueryParser is functional
231     my $QParser = C4::Context->queryparser();
232     my $queryparser_error = {};
233     if ( ! defined $QParser || ref($QParser) ne 'Koha::QueryParser::Driver::PQF' ) {
234         # Error initializing the QueryParser object
235         # Get the used queryparser.yaml file path to report the user
236         $queryparser_error->{ fallback } = ( defined $queryparser_file ) ? 0 : 1;
237         $queryparser_error->{ file }     = ( defined $queryparser_file )
238                                                 ? $queryparser_file
239                                                 : $queryparser_fallback_file;
240         # Report error data to the template
241         $template->param( QueryParserError => $queryparser_error );
242     } else {
243         # Check for an absent queryparser_config entry in koha-conf.xml
244         if ( ! defined $queryparser_file ) {
245             # Not an error but a warning for the missing entry in koha-conf-xml
246             push @xml_config_warnings, {
247                     error => 'queryparser_entry_missing',
248                     file  => $queryparser_fallback_file
249             };
250         }
251     }
252 }
253
254 # Test Zebra facets configuration
255 if ( !defined C4::Context->config('use_zebra_facets') ) {
256     push @xml_config_warnings, { error => 'use_zebra_facets_entry_missing' };
257 }
258
259 # ILL module checks
260 if ( C4::Context->preference('ILLModule') ) {
261     my $warnILLConfiguration = 0;
262     my $ill_config_from_file = C4::Context->config("interlibrary_loans");
263     my $ill_config = Koha::Illrequest::Config->new;
264
265     my $available_ill_backends =
266       ( scalar @{ $ill_config->available_backends } > 0 );
267
268     # Check backends
269     if ( !$available_ill_backends ) {
270         $template->param( no_ill_backends => 1 );
271         $warnILLConfiguration = 1;
272     }
273
274     # Check partner_code
275     if ( !Koha::Patron::Categories->find($ill_config->partner_code) ) {
276         $template->param( ill_partner_code_doesnt_exist => $ill_config->partner_code );
277         $warnILLConfiguration = 1;
278     }
279
280     if ( !$ill_config_from_file->{partner_code} ) {
281         # partner code not defined
282         $template->param( ill_partner_code_not_defined => 1 );
283         $warnILLConfiguration = 1;
284     }
285
286
287     if ( !$ill_config_from_file->{branch} ) {
288         # branch not defined
289         $template->param( ill_branch_not_defined => 1 );
290         $warnILLConfiguration = 1;
291     }
292
293     $template->param( warnILLConfiguration => $warnILLConfiguration );
294 }
295
296 if ( C4::Context->preference('SearchEngine') eq 'Elasticsearch' ) {
297     # Check ES configuration health and runtime status
298
299     my $es_status;
300     my $es_config_error;
301     my $es_running = 1;
302
303     my $es_conf;
304     try {
305         $es_conf = Koha::SearchEngine::Elasticsearch::_read_configuration();
306     }
307     catch {
308         if ( ref($_) eq 'Koha::Exceptions::Config::MissingEntry' ) {
309             $template->param( elasticsearch_fatal_config_error => $_->message );
310             $es_config_error = 1;
311         }
312     };
313     if ( !$es_config_error ) {
314
315         my $biblios_index_name     = $es_conf->{index_name} . "_" . $Koha::SearchEngine::BIBLIOS_INDEX;
316         my $authorities_index_name = $es_conf->{index_name} . "_" . $Koha::SearchEngine::AUTHORITIES_INDEX;
317
318         my @indexes = ($biblios_index_name, $authorities_index_name);
319         # TODO: When new indexes get added, we could have other ways to
320         #       fetch the list of available indexes (e.g. plugins, etc)
321         $es_status->{nodes} = $es_conf->{nodes};
322         my $es = Search::Elasticsearch->new({ nodes => $es_conf->{nodes} });
323
324         foreach my $index ( @indexes ) {
325             my $count;
326             try {
327                 $count = $es->indices->stats( index => $index )
328                       ->{_all}{primaries}{docs}{count};
329             }
330             catch {
331                 if ( ref($_) eq 'Search::Elasticsearch::Error::Missing' ) {
332                     push @{ $es_status->{errors} }, "Index not found ($index)";
333                     $count = -1;
334                 }
335                 elsif ( ref($_) eq 'Search::Elasticsearch::Error::NoNodes' ) {
336                     $es_running = 0;
337                 }
338                 else {
339                     # TODO: when time comes, we will cover more use cases
340                     die $_;
341                 }
342             };
343
344             push @{ $es_status->{indexes} },
345               {
346                 index_name => $index,
347                 count      => $count
348               };
349         }
350         $es_status->{running} = $es_running;
351
352         $template->param( elasticsearch_status => $es_status );
353     }
354 }
355
356 if ( C4::Context->preference('RESTOAuth2ClientCredentials') ) {
357     # Do we have the required deps?
358     unless ( can_load( modules => { 'Net::OAuth2::AuthorizationServer' => undef }) ) {
359         $template->param( oauth2_missing_deps => 1 );
360     }
361 }
362
363 # Sco Patron should not contain any other perms than circulate => self_checkout
364 if (  C4::Context->preference('WebBasedSelfCheck')
365       and C4::Context->preference('AutoSelfCheckAllowed')
366 ) {
367     my $userid = C4::Context->preference('AutoSelfCheckID');
368     my $all_permissions = C4::Auth::get_user_subpermissions( $userid );
369     my ( $has_self_checkout_perm, $has_other_permissions );
370     while ( my ( $module, $permissions ) = each %$all_permissions ) {
371         if ( $module eq 'self_check' ) {
372             while ( my ( $permission, $flag ) = each %$permissions ) {
373                 if ( $permission eq 'self_checkout_module' ) {
374                     $has_self_checkout_perm = 1;
375                 } else {
376                     $has_other_permissions = 1;
377                 }
378             }
379         } else {
380             $has_other_permissions = 1;
381         }
382     }
383     $template->param(
384         AutoSelfCheckPatronDoesNotHaveSelfCheckPerm => not ( $has_self_checkout_perm ),
385         AutoSelfCheckPatronHasTooManyPerm => $has_other_permissions,
386     );
387 }
388
389 # Test YAML system preferences
390 # FIXME: This is list of current YAML formatted prefs, should by type of preference
391 my @yaml_prefs = (
392     "UpdateNotForLoanStatusOnCheckin",
393     "OpacHiddenItems",
394     "BibtexExportAdditionalFields",
395     "RisExportAdditionalFields",
396     "UpdateItemWhenLostFromHoldList",
397     "MarcFieldsToOrder",
398     "MarcItemFieldsToOrder",
399     "UpdateitemLocationOnCheckin",
400     "ItemsDeniedRenewal"
401 );
402 my @bad_yaml_prefs;
403 foreach my $syspref (@yaml_prefs) {
404     my $yaml = C4::Context->preference( $syspref );
405     if ( $yaml ) {
406         eval { YAML::Load( "$yaml\n\n" ); };
407         if ($@) {
408             push @bad_yaml_prefs, $syspref;
409         }
410     }
411 }
412 $template->param( 'bad_yaml_prefs' => \@bad_yaml_prefs ) if @bad_yaml_prefs;
413
414 {
415     my $dbh       = C4::Context->dbh;
416     my $patrons = $dbh->selectall_arrayref(
417         q|select b.borrowernumber from borrowers b join deletedborrowers db on b.borrowernumber=db.borrowernumber|,
418         { Slice => {} }
419     );
420     my $biblios = $dbh->selectall_arrayref(
421         q|select b.biblionumber from biblio b join deletedbiblio db on b.biblionumber=db.biblionumber|,
422         { Slice => {} }
423     );
424     my $items = $dbh->selectall_arrayref(
425         q|select i.itemnumber from items i join deleteditems di on i.itemnumber=di.itemnumber|,
426         { Slice => {} }
427     );
428     my $checkouts = $dbh->selectall_arrayref(
429         q|select i.issue_id from issues i join old_issues oi on i.issue_id=oi.issue_id|,
430         { Slice => {} }
431     );
432     my $holds = $dbh->selectall_arrayref(
433         q|select r.reserve_id from reserves r join old_reserves o on r.reserve_id=o.reserve_id|,
434         { Slice => {} }
435     );
436     if ( @$patrons or @$biblios or @$items or @$checkouts or @$holds ) {
437         $template->param(
438             has_ai_issues => 1,
439             ai_patrons    => $patrons,
440             ai_biblios    => $biblios,
441             ai_items      => $items,
442             ai_checkouts  => $checkouts,
443             ai_holds      => $holds,
444         );
445     }
446 }
447
448 # Circ rule warnings
449 {
450     my $dbh   = C4::Context->dbh;
451     my $units = $dbh->selectall_arrayref(
452         q|SELECT branchcode, categorycode, itemtype, lengthunit FROM issuingrules WHERE lengthunit NOT IN ( 'days', 'hours' ); |,
453         { Slice => {} }
454     );
455
456     if (@$units) {
457         $template->param(
458             warnIssuingRules => 1,
459             ir_units         => $units,
460         );
461     }
462 }
463
464 # Guarantor relationships warnings
465 {
466     my $dbh   = C4::Context->dbh;
467     my ($bad_relationships_count) = $dbh->selectall_arrayref(q{
468         SELECT COUNT(*)
469         FROM (
470             SELECT relationship FROM borrower_relationships WHERE relationship='_bad_data'
471             UNION ALL
472             SELECT relationship FROM borrowers WHERE relationship='_bad_data') a
473     });
474
475     $bad_relationships_count = $bad_relationships_count->[0]->[0];
476
477     my $existing_relationships = $dbh->selectall_arrayref(q{
478           SELECT DISTINCT(relationship)
479           FROM (
480               SELECT relationship FROM borrower_relationships WHERE relationship IS NOT NULL
481               UNION ALL
482               SELECT relationship FROM borrowers WHERE relationship IS NOT NULL) a
483     });
484
485     my %valid_relationships = map { $_ => 1 } split( /,|\|/, C4::Context->preference('borrowerRelationship') );
486     $valid_relationships{ _bad_data } = 1; # we handle this case in another way
487
488     my $wrong_relationships = [ grep { !$valid_relationships{ $_->[0] } } @{$existing_relationships} ];
489     if ( $wrong_relationships or $bad_relationships_count ) {
490
491         $template->param(
492             warnRelationships => 1,
493         );
494
495         if ( $wrong_relationships ) {
496             $template->param(
497                 wrong_relationships => $wrong_relationships
498             );
499         }
500         if ($bad_relationships_count) {
501             $template->param(
502                 bad_relationships_count => $bad_relationships_count,
503             );
504         }
505     }
506 }
507
508 my %versions = C4::Context::get_versions();
509
510 $template->param(
511     kohaVersion   => $versions{'kohaVersion'},
512     osVersion     => $versions{'osVersion'},
513     perlPath      => $perl_path,
514     perlVersion   => $versions{'perlVersion'},
515     perlIncPath   => [ map { perlinc => $_ }, @INC ],
516     mysqlVersion  => $versions{'mysqlVersion'},
517     apacheVersion => $versions{'apacheVersion'},
518     zebraVersion  => $zebraVersion,
519     prefBiblioAddsAuthorities => $prefBiblioAddsAuthorities,
520     prefAutoCreateAuthorities => $prefAutoCreateAuthorities,
521     warnPrefBiblioAddsAuthorities => $warnPrefBiblioAddsAuthorities,
522     warnPrefEasyAnalyticalRecords  => $warnPrefEasyAnalyticalRecords,
523     warnPrefAnonymousPatron => $warnPrefAnonymousPatron,
524     warnPrefAnonymousPatron_PatronDoesNotExist => $warnPrefAnonymousPatron_PatronDoesNotExist,
525     errZebraConnection => $errZebraConnection,
526     warnIsRootUser => $warnIsRootUser,
527     warnNoActiveCurrency => $warnNoActiveCurrency,
528     warnNoTemplateCaching => ( C4::Context->config('template_cache_dir') ? 0 : 1 ),
529     xml_config_warnings => \@xml_config_warnings,
530     warnStatisticsFieldsError => $warnStatisticsFieldsError,
531 );
532
533 my @components = ();
534
535 my $perl_modules = C4::Installer::PerlModules->new;
536 $perl_modules->versions_info;
537
538 my @pm_types = qw(missing_pm upgrade_pm current_pm);
539
540 foreach my $pm_type(@pm_types) {
541     my $modules = $perl_modules->get_attr($pm_type);
542     foreach (@$modules) {
543         my ($module, $stats) = each %$_;
544         push(
545             @components,
546             {
547                 name    => $module,
548                 version => $stats->{'cur_ver'},
549                 missing => ($pm_type eq 'missing_pm' ? 1 : 0),
550                 upgrade => ($pm_type eq 'upgrade_pm' ? 1 : 0),
551                 current => ($pm_type eq 'current_pm' ? 1 : 0),
552                 require => $stats->{'required'},
553                 reqversion => $stats->{'min_ver'},
554             }
555         );
556     }
557 }
558
559 @components = sort {$a->{'name'} cmp $b->{'name'}} @components;
560
561 my $counter=0;
562 my $row = [];
563 my $table = [];
564 foreach (@components) {
565     push (@$row, $_);
566     unless (++$counter % 4) {
567         push (@$table, {row => $row});
568         $row = [];
569     }
570 }
571 # Processing the last line (if there are any modules left)
572 if (scalar(@$row) > 0) {
573     # Extending $row to the table size
574     $$row[3] = '';
575     # Pushing the last line
576     push (@$table, {row => $row});
577 }
578 ## ## $table
579
580 $template->param( table => $table );
581
582
583 ## ------------------------------------------
584 ## Koha contributions
585 my $docdir;
586 if ( defined C4::Context->config('docdir') ) {
587     $docdir = C4::Context->config('docdir');
588 } else {
589     # if no <docdir> is defined in koha-conf.xml, use the default location
590     # this is a work-around to stop breakage on upgraded Kohas, bug 8911
591     $docdir = C4::Context->config('intranetdir') . '/docs';
592 }
593
594 ## Release teams
595 my $teams =
596   -e "$docdir" . "/teams.yaml"
597   ? LoadFile( "$docdir" . "/teams.yaml" )
598   : {};
599 my $dev_team = (sort {$b <=> $a} (keys %{$teams->{team}}))[0];
600 my $short_version = substr($versions{'kohaVersion'},0,5);
601 my $minor = substr($versions{'kohaVersion'},3,2);
602 my $development_version = ( $minor eq '05' || $minor eq '11' ) ? 0 : 1;
603 $template->param( short_version => $short_version );
604 $template->param( development_version => $development_version );
605
606 ## Contributors
607 my $contributors =
608   -e "$docdir" . "/contributors.yaml"
609   ? LoadFile( "$docdir" . "/contributors.yaml" )
610   : {};
611 for my $version ( sort { $a <=> $b } keys %{$teams->{team}} ) {
612     for my $role ( keys %{ $teams->{team}->{$version} } ) {
613         my $normalized_role = "$role";
614         $normalized_role =~ s/s$//;
615         if ( ref( $teams->{team}->{$version}->{$role} ) eq 'ARRAY' ) {
616             for my $contributor ( @{ $teams->{team}->{$version}->{$role} } ) {
617                 my $name = $contributor->{name};
618                 # Add role to contributors
619                 push @{ $contributors->{$name}->{roles}->{$normalized_role} },
620                   $version;
621                 # Add openhub to teams
622                 if ( exists( $contributors->{$name}->{openhub} ) ) {
623                     $contributor->{openhub} = $contributors->{$name}->{openhub};
624                 }
625             }
626         }
627         elsif ( $role ne 'release_date' ) {
628             my $name = $teams->{team}->{$version}->{$role}->{name};
629             # Add role to contributors
630             push @{ $contributors->{$name}->{roles}->{$normalized_role} },
631               $version;
632             # Add openhub to teams
633             if ( exists( $contributors->{$name}->{openhub} ) ) {
634                 $teams->{team}->{$version}->{$role}->{openhub} =
635                   $contributors->{$name}->{openhub};
636             }
637         }
638         else {
639             $teams->{team}->{$version}->{$role} = DateTime->from_epoch( epoch => $teams->{team}->{$version}->{$role});
640         }
641     }
642 }
643
644 ## Create last name ordered array of people from contributors
645 my @people = map {
646     { name => $_, ( $contributors->{$_} ? %{ $contributors->{$_} } : () ) }
647 } sort {
648     my ($alast) = ( split( /\s/, $a ) )[-1];
649     my ($blast) = ( split( /\s/, $b ) )[-1];
650     lc($alast) cmp lc($blast)
651 } keys %{$contributors};
652
653 $template->param( contributors => \@people );
654 $template->param( maintenance_team => $teams->{team}->{$dev_team} );
655 $template->param( release_team => $teams->{team}->{$short_version} );
656
657 ## Timeline
658 if ( open( my $file, "<:encoding(UTF-8)", "$docdir" . "/history.txt" ) ) {
659
660     my $i = 0;
661
662     my @rows2 = ();
663     my $row2  = [];
664
665     my @lines = <$file>;
666     close($file);
667
668     shift @lines; #remove header row
669
670     foreach (@lines) {
671         my ( $epoch, $date, $desc, $tag ) = split(/\t/);
672         if(!$desc && $date=~ /(?<=\d{4})\s+/) {
673             ($date, $desc)= ($`, $');
674         }
675         push(
676             @rows2,
677             {
678                 date => $date,
679                 desc => $desc,
680             }
681         );
682     }
683
684     my $table2 = [];
685     #foreach my $row2 (@rows2) {
686     foreach  (@rows2) {
687         push (@$row2, $_);
688         push( @$table2, { row2 => $row2 } );
689         $row2 = [];
690     }
691
692     $template->param( table2 => $table2 );
693 } else {
694     $template->param( timeline_read_error => 1 );
695 }
696
697 output_html_with_http_headers $query, $cookie, $template->output;