Bugzilla – Attachment 193511 Details for
Bug 41895
Introduce Koha::Context::UserEnv to reduce circ deps problem
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 41895: Introduce Koha::Context::UserEnv
905fc28.patch (text/plain), 3.56 KB, created by
Jonathan Druart
on 2026-02-20 10:25:22 UTC
(
hide
)
Description:
Bug 41895: Introduce Koha::Context::UserEnv
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2026-02-20 10:25:22 UTC
Size:
3.56 KB
patch
obsolete
>From 905fc28b163c067705ccd31502483753b15de125 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Fri, 20 Feb 2026 11:21:02 +0100 >Subject: [PATCH] Bug 41895: Introduce Koha::Context::UserEnv > >Introduce Koha::Context::UserEnv to reduce circ deps problem >--- > C4/Context.pm | 12 ++++++---- > Koha/Context/UserEnv.pm | 47 ++++++++++++++++++++++++++++++++++++++ > Koha/Middleware/UserEnv.pm | 6 +++-- > 3 files changed, 58 insertions(+), 7 deletions(-) > create mode 100644 Koha/Context/UserEnv.pm > >diff --git a/C4/Context.pm b/C4/Context.pm >index 3971236de53..24700702068 100644 >--- a/C4/Context.pm >+++ b/C4/Context.pm >@@ -21,6 +21,8 @@ use Modern::Perl; > > use vars qw($AUTOLOAD $context); > >+our $REQUEST_ENV; >+ > BEGIN { > if ( $ENV{'HTTP_USER_AGENT'} ) { # Only hit when plack is not enabled > >@@ -50,6 +52,7 @@ use Koha::Config::SysPrefs; > use Koha::Context::Preferences; > use Koha::Config; > use Koha; >+use Koha::Context::UserEnv; > > =head1 NAME > >@@ -646,7 +649,7 @@ Retrieves a hash for user environment variables. > =cut > > sub userenv { >- return $context->{userenv}; >+ return Koha::Context::UserEnv->get_all(); > } > > =head2 set_userenv_from_session >@@ -699,7 +702,7 @@ sub set_userenv { > $register_id, $register_name, $session_id, > ) = @_; > >- my $cell = { >+ my $userenv = { > "number" => $usernum, > "id" => $userid, > "cardnumber" => $usercnum, >@@ -718,8 +721,7 @@ sub set_userenv { > "register_name" => $register_name, > "session_id" => $session_id, > }; >- $context->{userenv} = $cell; >- return $cell; >+ return Koha::Context::UserEnv->attach($userenv); > } > > =head2 unset_userenv >@@ -731,7 +733,7 @@ Destroys user environment variables. > =cut > > sub unset_userenv { >- $context->{userenv} = undef; >+ return Koha::Context::UserEnv->clear(); > } > > =head2 get_versions >diff --git a/Koha/Context/UserEnv.pm b/Koha/Context/UserEnv.pm >new file mode 100644 >index 00000000000..751bcc973df >--- /dev/null >+++ b/Koha/Context/UserEnv.pm >@@ -0,0 +1,47 @@ >+package Koha::Context::UserEnv; >+ >+use Modern::Perl; >+ >+our $REQUEST_ENV; >+ >+sub attach { >+ my ( $class, $userenv ) = @_; >+ >+ die "userenv must be hashref" >+ unless ref $userenv eq 'HASH'; >+ >+ die "No request env" unless $REQUEST_ENV; >+ >+ $REQUEST_ENV->{'koha.userenv'} = $userenv; >+ return $userenv; >+} >+ >+sub get_all { >+ return unless $REQUEST_ENV; >+ return $REQUEST_ENV->{'koha.userenv'}; >+} >+ >+sub get { >+ my ( $class, $key ) = @_; >+ return unless $REQUEST_ENV && $REQUEST_ENV->{'koha.userenv'}; >+ return $REQUEST_ENV->{'koha.userenv'}->{$key}; >+} >+ >+sub set { >+ my ( $class, $key, $value ) = @_; >+ die "No userenv attached" unless $REQUEST_ENV && $REQUEST_ENV->{'koha.userenv'}; >+ >+ $REQUEST_ENV->{'koha.userenv'}->{$key} = $value; >+ return $value; >+} >+ >+sub clear { >+ return unless $REQUEST_ENV; >+ delete $REQUEST_ENV->{'koha.userenv'}; >+} >+ >+sub exists { >+ return exists $REQUEST_ENV->{'koha.userenv'}; >+} >+ >+1; >diff --git a/Koha/Middleware/UserEnv.pm b/Koha/Middleware/UserEnv.pm >index 14aef47b799..3e94bf0ad81 100644 >--- a/Koha/Middleware/UserEnv.pm >+++ b/Koha/Middleware/UserEnv.pm >@@ -3,7 +3,7 @@ use Modern::Perl; > > use parent qw(Plack::Middleware); > >-use C4::Context; >+use Koha::Context::UserEnv; > > =head1 NAME > >@@ -22,7 +22,9 @@ sub call { > > my $req = Plack::Request->new($env); > >- C4::Context->unset_userenv; >+ local $Koha::Context::UserEnv::REQUEST_ENV = $env; >+ >+ Koha::Context::UserEnv->attach( {} ); > > return $self->app->($env); > } >-- >2.43.0 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 41895
: 193511 |
193516
|
193519