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