[Koha-patches] [PATCH] C4::Context::import reloaded

Marc Chantreux marc.chantreux at biblibre.com
Wed Jul 30 13:27:57 CEST 2008


the problem was a context was stored every time C4::Context was called.
---
 C4/Context.pm |   23 +++++++++++++++--------
 1 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/C4/Context.pm b/C4/Context.pm
index 20e5794..0e3fcf2 100644
--- a/C4/Context.pm
+++ b/C4/Context.pm
@@ -254,14 +254,21 @@ sub db_scheme2dbi {
 }
 
 sub import {
-    my $package = shift;
-    my $conf_fname = shift;        # Config file name
-
-    # Create a new context from the given config file name, if
-    # any, then set it as the current context.
-    $context = new C4::Context($conf_fname) unless $context;
-    return undef if !defined($context);
-    $context->set_context;
+    # Create the default context ($C4::Context::Context)
+    # the first time the module is called
+    # (a config file can be optionaly passed)
+
+    # default context allready exists? 
+    return if $context;
+
+    # no ? so load it!
+    my ($pkg,$config_file) = @_ ;
+    my $new_ctx = __PACKAGE__->new($config_file);
+    return unless $new_ctx;
+
+    # if successfully loaded, use it by default
+    $new_ctx->set_context;
+    1;
 }
 
 =item new
-- 
1.5.4.3




More information about the Koha-patches mailing list