Bugzilla – Attachment 167383 Details for
Bug 36367
Remove context stack
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36367: Remove context stack
Bug-36367-Remove-context-stack.patch (text/plain), 5.26 KB, created by
Martin Renvoize (ashimema)
on 2024-06-04 12:10:55 UTC
(
hide
)
Description:
Bug 36367: Remove context stack
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-06-04 12:10:55 UTC
Size:
5.26 KB
patch
obsolete
>From 274d487b932fa0868b1b2802eb6e2f79d9be0daa 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 36367: Remove context stack > >We are not using it and it's confusing, let's remove the context stack. > >Signed-off-by: Julian Maurice <julian.maurice@biblibre.com> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > 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 8c101c01b71..6aa8fd36867 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"); >@@ -700,9 +650,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>. > >@@ -746,9 +693,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.45.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 36367
:
163500
|
163501
|
163502
|
163503
|
163504
|
163505
|
163506
|
163507
|
163508
|
165115
|
165116
|
165117
|
165118
|
165119
|
165120
|
165121
|
165122
|
165123
|
165124
|
165125
|
165126
|
167380
|
167381
|
167382
| 167383 |
167384
|
167385
|
167386
|
167387
|
167388
|
167389
|
167390
|
167391