Bugzilla – Attachment 163041 Details for
Bug 36149
userenv stored in plack worker's memory and survive from one request to another
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36149: Remove context stack
Bug-36149-Remove-context-stack.patch (text/plain), 5.14 KB, created by
Jonathan Druart
on 2024-03-11 14:25:01 UTC
(
hide
)
Description:
Bug 36149: Remove context stack
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2024-03-11 14:25:01 UTC
Size:
5.14 KB
patch
obsolete
>From d111cc85b27826b8e2f0913c8f88e0d9c1f97d63 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 11 Mar 2024 14:45:40 +0100 >Subject: [PATCH] Bug 36149: Remove context stack > >We are not using it and it's confusing, let's remove the context stack. >--- > C4/Context.pm | 58 +-------------------------------------- > misc/cronjobs/cloud-kw.pl | 7 ++--- > 2 files changed, 4 insertions(+), 61 deletions(-) > >diff --git a/C4/Context.pm b/C4/Context.pm >index 2b022c69342..f08b391ab62 100644 >--- a/C4/Context.pm >+++ b/C4/Context.pm >@@ -19,7 +19,7 @@ package C4::Context; > > use Modern::Perl; > >-use vars qw($AUTOLOAD $context @context_stack); >+use vars qw($AUTOLOAD $context); > BEGIN { > if ( $ENV{'HTTP_USER_AGENT'} ) { # Only hit when plack is not enabled > >@@ -79,18 +79,6 @@ This module takes care of setting up the context for a script: > figuring out which configuration file to load, and loading it, opening > a connection to the right database, and so forth. > >-Most scripts will only use one context. They can simply have >- >- use C4::Context; >- >-at the top. >- >-Other scripts may need to use several contexts. For instance, if a >-library has two databases, one for a certain collection, and the other >-for everything else, it might be necessary for a script to use two >-different contexts to search both databases. Such scripts should use >-the C<&set_context> and C<&restore_context> functions, below. >- > By default, C4::Context reads the configuration from > F</etc/koha/koha-conf.xml>. This may be overridden by setting the C<$KOHA_CONF> > environment variable to the pathname of a configuration file to use. >@@ -116,7 +104,6 @@ environment variable to the pathname of a configuration file to use. > # A connection object for the Zebra server > > $context = undef; # Initially, no context is set >-@context_stack = (); # Initially, no saved contexts > > sub import { > # Create the default context ($C4::Context::Context) >@@ -196,14 +183,6 @@ sub new { > or > set_context C4::Context $context; > >- ... >- restore_context C4::Context; >- >-In some cases, it might be necessary for a script to use multiple >-contexts. C<&set_context> saves the current context on a stack, then >-sets the context to C<$context>, which will be used in future >-operations. To restore the previous context, use C<&restore_context>. >- > =cut > > #' >@@ -230,39 +209,10 @@ sub set_context > $new_context = $self; > } > >- # Save the old context, if any, on the stack >- push @context_stack, $context if defined($context); >- > # Set the new context > $context = $new_context; > } > >-=head2 restore_context >- >- &restore_context; >- >-Restores the context set by C<&set_context>. >- >-=cut >- >-#' >-sub restore_context >-{ >- my $self = shift; >- >- if ($#context_stack < 0) >- { >- # Stack underflow. >- die "Context stack underflow"; >- } >- >- # Pop the old context and set it. >- $context = pop @context_stack; >- >- # FIXME - Should this return something, like maybe the context >- # that was current when this was called? >-} >- > =head2 config > > $value = C4::Context->config("config_variable"); >@@ -699,9 +649,6 @@ sub new_dbh > ... > C4::Connect->restore_dbh; > >-C<&set_dbh> and C<&restore_dbh> work in a manner analogous to >-C<&set_context> and C<&restore_context>. >- > C<&set_dbh> saves the current database handle on a stack, then sets > the current database handle to C<$my_dbh>. > >@@ -745,9 +692,6 @@ sub restore_dbh > > # Pop the old database handle and set it. > $context->{"dbh"} = pop @{$context->{"dbh_stack"}}; >- >- # FIXME - If it is determined that restore_context should >- # return something, then this function should, too. > } > > =head2 userenv >diff --git a/misc/cronjobs/cloud-kw.pl b/misc/cronjobs/cloud-kw.pl >index 08c37c45355..33c6a56013b 100755 >--- a/misc/cronjobs/cloud-kw.pl >+++ b/misc/cronjobs/cloud-kw.pl >@@ -27,7 +27,7 @@ use Pod::Usage qw( pod2usage ); > use Getopt::Long qw( GetOptions ); > > use Koha::Script -cron; >-use C4::Context; >+use C4::Context qw($context); > use C4::Log qw( cronlogaction ); > > my $verbose = 0; >@@ -58,6 +58,7 @@ eval { > }; > croak "Unable to read configuration file: $conf\n" if $@; > >+my $original_context = $C4::Context::context; > for my $cloud ( @clouds ) { > print "Create a cloud\n", > " Koha conf file: ", $cloud->{KohaConf} ? $cloud->{KohaConf} : "default", "\n", >@@ -69,12 +70,10 @@ for my $cloud ( @clouds ) { > if $verbose; > > # Set Koha context if KohaConf is present >- my $set_new_context = 0; > if ( $cloud->{KohaConf} ) { > if ( -e $cloud->{KohaConf} ) { > my $context = C4::Context->new( $cloud->{KohaConf} ); > $context->set_context(); >- $set_new_context = 1; > } > else { > carp "Koha conf file doesn't exist: ", $cloud->{KohaConf}, " ; use KOHA_CONF\n"; >@@ -90,8 +89,8 @@ for my $cloud ( @clouds ) { > my $withcss = $cloud->{Withcss} =~ /^yes/i; > print $fh $index->html_cloud( $cloud->{KohaIndex}, $withcss ); > close $fh; >- $set_new_context && restore_context C4::Context; > } >+$original_context->set_context; > > cronlogaction({ action => 'End', info => "COMPLETED" }); > >-- >2.34.1
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 36149
:
163039
|
163040
|
163041
|
163042
|
163043
|
163402
|
163403
|
163404
|
163406
|
163407
|
163409
|
163412
|
163499
|
164145
|
164146
|
164555
|
164567
|
164568
|
164569