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