C4::Context::import reloaded
authorMarc Chantreux <marc.chantreux@biblibre.com>
Wed, 30 Jul 2008 11:27:57 +0000 (13:27 +0200)
committerJoshua Ferraro <jmf@liblime.com>
Fri, 1 Aug 2008 03:41:32 +0000 (22:41 -0500)
the problem was a context was stored every time C4::Context was called.

Signed-off-by: Joshua Ferraro <jmf@liblime.com>
C4/Context.pm

index d2ceb42..7813f49 100644 (file)
@@ -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