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