From 55260c68bd9809d2f6fdf5bc6a9ad6fbdb80cbe0 Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Fri, 2 Sep 2016 12:30:33 +0200 Subject: [PATCH] Bug 17240: (prepare) Allow processes that rely on background jobs run in Plack mode This adds prepares the main one by adding method "is_psgi" to C4::Context and using it in C4::Auth for all templates. It is used by about.pl and Koha::AuthUtils. Test plan : - On a Koha running with Plack - Go to about.pl - Look at line "PGSI:" => You should see "Plack" - Enable CAS authentication - Go to OPAC auth page - Look at the CAS link => You see the current page in this URL --- C4/Auth.pm | 1 + C4/Context.pm | 12 ++++++++++++ Koha/AuthUtils.pm | 3 +-- about.pl | 4 +--- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index 2731ff2..04a6411 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -466,6 +466,7 @@ sub get_template_and_user { marcflavour => C4::Context->preference("marcflavour"), OPACBaseURL => C4::Context->preference('OPACBaseURL'), minPasswordLength => $minPasswordLength, + is_psgi => C4::Context->is_psgi ? 1 : 0, ); if ( $in->{'type'} eq "intranet" ) { $template->param( diff --git a/C4/Context.pm b/C4/Context.pm index 41bce3b..2ca14e6 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -97,6 +97,7 @@ use File::Spec; use Module::Load::Conditional qw(can_load); use POSIX (); use ZOOM; +use List::MoreUtils qw(any); use C4::Boolean; use C4::Debug; @@ -1087,6 +1088,17 @@ sub temporary_directory { return C4::Context->config('tmp_path') || File::Spec->tmpdir; } +=head2 interface + + C4::Context->is_psgi + + Returns if using PSGI mode (Plack) instead of CGI mode + +=cut + +sub is_psgi { + return any { /(^psgi\.|^plack\.)/i } keys %ENV; +} 1; diff --git a/Koha/AuthUtils.pm b/Koha/AuthUtils.pm index a42705f..d49388b 100644 --- a/Koha/AuthUtils.pm +++ b/Koha/AuthUtils.pm @@ -21,7 +21,6 @@ use Modern::Perl; use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64); use Encode qw( encode is_utf8 ); use Fcntl qw/O_RDONLY/; # O_RDONLY is used in generate_salt -use List::MoreUtils qw/ any /; use String::Random qw( random_string ); use C4::Context; @@ -193,7 +192,7 @@ outside this context. sub get_script_name { # This is the method about.pl uses to detect Plack; now that two places use it, it MUST be # right. - if ( ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) && $ENV{SCRIPT_NAME} =~ m,^/(intranet|opac)(.*), ) { + if ( C4::Context->is_psgi && $ENV{SCRIPT_NAME} =~ m,^/(intranet|opac)(.*), ) { return '/cgi-bin/koha' . $2; } else { return $ENV{SCRIPT_NAME}; diff --git a/about.pl b/about.pl index a79fc2c..5dd1ca2 100755 --- a/about.pl +++ b/about.pl @@ -25,7 +25,6 @@ use Modern::Perl; use CGI qw ( -utf8 ); use DateTime::TimeZone; use File::Spec; -use List::MoreUtils qw/ any /; use LWP::Simple; use Module::Load::Conditional qw(can_load); use XML::Simple; @@ -105,9 +104,8 @@ if ($^O ne 'VMS') { my $zebraVersion = `zebraidx -V`; # Check running PSGI env -if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { +if ( C4::Context->is_psgi ) { $template->param( - is_psgi => 1, psgi_server => ($ENV{ PLACK_ENV }) ? "Plack ($ENV{PLACK_ENV})" : ($ENV{ MOD_PERL }) ? "mod_perl ($ENV{MOD_PERL})" : 'Unknown' -- 2.7.4