View | Details | Raw Unified | Return to bug 15562
Collapse All | Expand All

(-)a/C4/Auth_with_cas.pm (-1 / +1 lines)
Lines 37-43 BEGIN { Link Here
37
	@ISA    = qw(Exporter);
37
	@ISA    = qw(Exporter);
38
	@EXPORT = qw(check_api_auth_cas checkpw_cas login_cas logout_cas login_cas_url);
38
	@EXPORT = qw(check_api_auth_cas checkpw_cas login_cas logout_cas login_cas_url);
39
}
39
}
40
my $context = C4::Context->new() or die 'C4::Context->new failed';
40
my $context = C4::Context->current() or die 'No current context';
41
my $defaultcasserver;
41
my $defaultcasserver;
42
my $casservers;
42
my $casservers;
43
my $yamlauthfile = C4::Context->config('intranetdir') . "/C4/Auth_cas_servers.yaml";
43
my $yamlauthfile = C4::Context->config('intranetdir') . "/C4/Auth_cas_servers.yaml";
(-)a/C4/Auth_with_ldap.pm (-1 / +1 lines)
Lines 54-60 sub ldapserver_error { Link Here
54
}
54
}
55
55
56
use vars qw($mapping @ldaphosts $base $ldapname $ldappassword);
56
use vars qw($mapping @ldaphosts $base $ldapname $ldappassword);
57
my $context = C4::Context->new() 	or die 'C4::Context->new failed';
57
my $context = C4::Context->current() 	or die 'No current context';
58
my $ldap = C4::Context->config("ldapserver") or die 'No "ldapserver" in server hash from KOHA_CONF: ' . $ENV{KOHA_CONF};
58
my $ldap = C4::Context->config("ldapserver") or die 'No "ldapserver" in server hash from KOHA_CONF: ' . $ENV{KOHA_CONF};
59
my $prefhost  = $ldap->{hostname}	or die ldapserver_error('hostname');
59
my $prefhost  = $ldap->{hostname}	or die ldapserver_error('hostname');
60
my $base      = $ldap->{base}		or die ldapserver_error('base');
60
my $base      = $ldap->{base}		or die ldapserver_error('base');
(-)a/C4/Context.pm (-167 / +144 lines)
Lines 31-37 BEGIN { Link Here
31
			    eval {C4::Context->dbh();};
31
			    eval {C4::Context->dbh();};
32
			    if ($@){
32
			    if ($@){
33
				$debug_level = 1;
33
				$debug_level = 1;
34
			    } 
34
			    }
35
			    else {
35
			    else {
36
				$debug_level =  C4::Context->preference("DebugLevel");
36
				$debug_level =  C4::Context->preference("DebugLevel");
37
			    }
37
			    }
Lines 49-55 BEGIN { Link Here
49
		# a little example table with various version info";
49
		# a little example table with various version info";
50
					print "
50
					print "
51
						<h1>Koha error</h1>
51
						<h1>Koha error</h1>
52
						<p>The following fatal error has occurred:</p> 
52
						<p>The following fatal error has occurred:</p>
53
                        <pre><code>$msg</code></pre>
53
                        <pre><code>$msg</code></pre>
54
						<table>
54
						<table>
55
						<tr><th>Apache</th><td>  $versions{apacheVersion}</td></tr>
55
						<tr><th>Apache</th><td>  $versions{apacheVersion}</td></tr>
Lines 63-73 BEGIN { Link Here
63
				} elsif ($debug_level eq "1"){
63
				} elsif ($debug_level eq "1"){
64
					print "
64
					print "
65
						<h1>Koha error</h1>
65
						<h1>Koha error</h1>
66
						<p>The following fatal error has occurred:</p> 
66
						<p>The following fatal error has occurred:</p>
67
                        <pre><code>$msg</code></pre>";
67
                        <pre><code>$msg</code></pre>";
68
				} else {
68
				} else {
69
					print "<p>production mode - trapped fatal error</p>";
69
					print "<p>production mode - trapped fatal error</p>";
70
				}       
70
				}
71
                print "</body></html>";
71
                print "</body></html>";
72
			}
72
			}
73
		#CGI::Carp::set_message(\&handle_errors);
73
		#CGI::Carp::set_message(\&handle_errors);
Lines 104-109 use Koha::Cache; Link Here
104
use POSIX ();
104
use POSIX ();
105
use DateTime::TimeZone;
105
use DateTime::TimeZone;
106
use Module::Load::Conditional qw(can_load);
106
use Module::Load::Conditional qw(can_load);
107
use Data::Dumper;
107
use Carp;
108
use Carp;
108
109
109
use C4::Boolean;
110
use C4::Boolean;
Lines 171-180 environment variable to the pathname of a configuration file to use. Link Here
171
#    file (/etc/koha/koha-conf.xml).
172
#    file (/etc/koha/koha-conf.xml).
172
# dbh
173
# dbh
173
#    A handle to the appropriate database for this context.
174
#    A handle to the appropriate database for this context.
174
# dbh_stack
175
#    Used by &set_dbh and &restore_dbh to hold other database
176
#    handles for this context.
177
# Zconn
178
#     A connection object for the Zebra server
175
#     A connection object for the Zebra server
179
176
180
# Koha's main configuration file koha-conf.xml
177
# Koha's main configuration file koha-conf.xml
Lines 183-189 environment variable to the pathname of a configuration file to use. Link Here
183
# 1. Path supplied via use C4::Context '/path/to/koha-conf.xml'
180
# 1. Path supplied via use C4::Context '/path/to/koha-conf.xml'
184
# 2. Path supplied in KOHA_CONF environment variable.
181
# 2. Path supplied in KOHA_CONF environment variable.
185
# 3. Path supplied in INSTALLED_CONFIG_FNAME, as long
182
# 3. Path supplied in INSTALLED_CONFIG_FNAME, as long
186
#    as value has changed from its default of 
183
#    as value has changed from its default of
187
#    '__KOHA_CONF_DIR__/koha-conf.xml', as happens
184
#    '__KOHA_CONF_DIR__/koha-conf.xml', as happens
188
#    when Koha is installed in 'standard' or 'single'
185
#    when Koha is installed in 'standard' or 'single'
189
#    mode.
186
#    mode.
Lines 193-244 environment variable to the pathname of a configuration file to use. Link Here
193
190
194
use constant CONFIG_FNAME => "/etc/koha/koha-conf.xml";
191
use constant CONFIG_FNAME => "/etc/koha/koha-conf.xml";
195
                # Default config file, if none is specified
192
                # Default config file, if none is specified
196
                
193
197
my $INSTALLED_CONFIG_FNAME = '__KOHA_CONF_DIR__/koha-conf.xml';
194
my $INSTALLED_CONFIG_FNAME = '__KOHA_CONF_DIR__/koha-conf.xml';
198
                # path to config file set by installer
195
                # path to config file set by installer
199
                # __KOHA_CONF_DIR__ is set by rewrite-confg.PL
196
                # __KOHA_CONF_DIR__ is set by rewrite-confg.PL
200
                # when Koha is installed in 'standard' or 'single'
197
                # when Koha is installed in 'standard' or 'single'
201
                # mode.  If Koha was installed in 'dev' mode, 
198
                # mode.  If Koha was installed in 'dev' mode,
202
                # __KOHA_CONF_DIR__ is *not* rewritten; instead
199
                # __KOHA_CONF_DIR__ is *not* rewritten; instead
203
                # developers should set the KOHA_CONF environment variable 
200
                # developers should set the KOHA_CONF environment variable
204
205
$context = undef;        # Initially, no context is set
206
@context_stack = ();        # Initially, no saved contexts
207
208
209
=head2 read_config_file
210
211
Reads the specified Koha config file. 
212
213
Returns an object containing the configuration variables. The object's
214
structure is a bit complex to the uninitiated ... take a look at the
215
koha-conf.xml file as well as the XML::Simple documentation for details. Or,
216
here are a few examples that may give you what you need:
217
201
218
The simple elements nested within the <config> element:
202
@context_stack = ();     # Initially, no saved contexts
219
203
220
    my $pass = $koha->{'config'}->{'pass'};
204
=head2 current
221
205
222
The <listen> elements:
206
Returns the current context
223
224
    my $listen = $koha->{'listen'}->{'biblioserver'}->{'content'};
225
226
The elements nested within the <server> element:
227
228
    my $ccl2rpn = $koha->{'server'}->{'biblioserver'}->{'cql2rpn'};
229
230
Returns undef in case of error.
231
207
232
=cut
208
=cut
233
209
234
sub read_config_file {		# Pass argument naming config file to read
210
sub current {
235
    my $koha = XMLin(shift, keyattr => ['id'], forcearray => ['listen', 'server', 'serverinfo'], suppressempty => '');
211
    return $context;
236
237
    if ($ismemcached) {
238
      $memcached->set('kohaconf',$koha);
239
    }
240
241
    return $koha;			# Return value: ref-to-hash holding the configuration
242
}
212
}
243
213
244
=head2 ismemcached
214
=head2 ismemcached
Lines 266-271 sub memcached { Link Here
266
    }
236
    }
267
}
237
}
268
238
239
sub db_driver {
240
    my $self = shift;
241
242
    $self = $context unless ref ($self);
243
    return unless $self;
244
245
    return $self->{db_driver};
246
}
247
269
=head2 db_scheme2dbi
248
=head2 db_scheme2dbi
270
249
271
    my $dbd_driver_name = C4::Context::db_schema2dbi($scheme);
250
    my $dbd_driver_name = C4::Context::db_schema2dbi($scheme);
Lines 286-317 sub import { Link Here
286
    # Create the default context ($C4::Context::Context)
265
    # Create the default context ($C4::Context::Context)
287
    # the first time the module is called
266
    # the first time the module is called
288
    # (a config file can be optionaly passed)
267
    # (a config file can be optionaly passed)
268
    # If ":no_config" is passed, no config load will be attempted
269
    # Config file defaults to either the file given by the $KOHA_CONF
270
    # environment variable, or /etc/koha/koha-conf.xml.
271
    # It saves the context values in the declared memcached server(s)
272
    # if currently available and uses those values until them expire and
273
    # re-reads them.
274
275
    my ($pkg,$config_file) = @_ ;
289
276
290
    # default context already exists?
277
    # default context already exists?
291
    return if $context;
278
    return if $context;
292
279
280
    if ($ismemcached) {
281
        # retrieve from memcached
282
        if (my $self = $memcached->get('kohaconf')) {
283
            $context = $self;
284
            return;
285
        }
286
    }
287
288
    # check that the specified config file exists and is not empty
289
    undef $config_file if defined $config_file &&
290
        !( ref($config_file) || openhandle($config_file) || -s $config_file );
291
    # Figure out a good config file to load if none was specified.
292
    if (!defined($config_file))
293
    {
294
        # If the $KOHA_CONF environment variable is set, use
295
        # that. Otherwise, use the built-in default.
296
        if ($ENV{'KOHA_CONF'} and ref($ENV{'KOHA_CONF'}) || -s  $ENV{"KOHA_CONF"}) {
297
            $config_file = $ENV{"KOHA_CONF"};
298
        } elsif ($INSTALLED_CONFIG_FNAME !~ /__KOHA_CONF_DIR/ and -s $INSTALLED_CONFIG_FNAME) {
299
            # NOTE: be careful -- don't change __KOHA_CONF_DIR in the above
300
            # regex to anything else -- don't want installer to rewrite it
301
            $config_file = $INSTALLED_CONFIG_FNAME;
302
        } elsif (-s CONFIG_FNAME) {
303
            $config_file = CONFIG_FNAME;
304
        } else {
305
            die "unable to locate Koha configuration file koha-conf.xml";
306
        }
307
    }
308
293
    # no ? so load it!
309
    # no ? so load it!
294
    my ($pkg,$config_file) = @_ ;
310
    return if $config_file && $config_file eq ":no_config";
295
    my $new_ctx = __PACKAGE__->new($config_file);
311
    my $new_ctx = __PACKAGE__->new($config_file);
296
    return unless $new_ctx;
312
    return unless $new_ctx;
297
313
298
    # if successfully loaded, use it by default
314
    # if successfully loaded, use it by default
299
    $new_ctx->set_context;
315
    $context = $new_ctx;
300
    1;
316
317
    if ($ismemcached) {
318
      $memcached->set('kohaconf',$new_ctx);
319
    }
301
}
320
}
302
321
322
use Scalar::Util qw(openhandle);
303
=head2 new
323
=head2 new
304
324
305
  $context = new C4::Context;
306
  $context = new C4::Context("/path/to/koha-conf.xml");
325
  $context = new C4::Context("/path/to/koha-conf.xml");
307
326
308
Allocates a new context. Initializes the context from the specified
327
Allocates a new context. Initializes the context from the specified
309
file, which defaults to either the file given by the C<$KOHA_CONF>
328
file.
310
environment variable, or F</etc/koha/koha-conf.xml>.
311
329
312
It saves the koha-conf.xml values in the declared memcached server(s)
330
XML structure is a bit complex to the uninitiated ... take a look at the
313
if currently available and uses those values until them expire and
331
koha-conf.xml file as well as the XML::Simple documentation for details. Or,
314
re-reads them.
332
here are a few examples that may give you what you need:
333
334
The simple elements nested within the <config> element:
335
336
    my $pass = $koha->{'config'}->{'pass'};
337
338
The <listen> elements:
339
340
    my $listen = $koha->{'listen'}->{'biblioserver'}->{'content'};
341
342
The elements nested within the <server> element:
343
344
    my $ccl2rpn = $koha->{'server'}->{'biblioserver'}->{'cql2rpn'};
345
346
Returns undef in case of error.
315
347
316
C<&new> does not set this context as the new default context; for
348
C<&new> does not set this context as the new default context; for
317
that, use C<&set_context>.
349
that, use C<&set_context>.
Lines 323-368 that, use C<&set_context>. Link Here
323
# 2004-08-10 A. Tarallo: Added check if the conf file is not empty
355
# 2004-08-10 A. Tarallo: Added check if the conf file is not empty
324
sub new {
356
sub new {
325
    my $class = shift;
357
    my $class = shift;
326
    my $conf_fname = shift;        # Config file to load
358
    my $conf_fname = shift or croak "No conf";
327
    my $self = {};
359
    my $namespace = shift;
328
360
329
    # check that the specified config file exists and is not empty
361
    my $self = XMLin(
330
    undef $conf_fname unless 
362
        $conf_fname,
331
        (defined $conf_fname && -s $conf_fname);
363
        keyattr => ['id'],
332
    # Figure out a good config file to load if none was specified.
364
        forcearray => ['listen', 'server', 'serverinfo'],
333
    if (!defined($conf_fname))
365
        suppressempty => '',
334
    {
366
    );
335
        # If the $KOHA_CONF environment variable is set, use
367
    die "Invalid config ".(ref($conf_fname) ? $$conf_fname : $conf_fname).": ".Dumper($self)
336
        # that. Otherwise, use the built-in default.
368
      unless ref($self) && $self->{"config"};
337
        if (exists $ENV{"KOHA_CONF"} and $ENV{'KOHA_CONF'} and -s  $ENV{"KOHA_CONF"}) {
338
            $conf_fname = $ENV{"KOHA_CONF"};
339
        } elsif ($INSTALLED_CONFIG_FNAME !~ /__KOHA_CONF_DIR/ and -s $INSTALLED_CONFIG_FNAME) {
340
            # NOTE: be careful -- don't change __KOHA_CONF_DIR in the above
341
            # regex to anything else -- don't want installer to rewrite it
342
            $conf_fname = $INSTALLED_CONFIG_FNAME;
343
        } elsif (-s CONFIG_FNAME) {
344
            $conf_fname = CONFIG_FNAME;
345
        } else {
346
            warn "unable to locate Koha configuration file koha-conf.xml";
347
            return;
348
        }
349
    }
350
    
351
    if ($ismemcached) {
352
        # retrieve from memcached
353
        $self = $memcached->get('kohaconf');
354
        if (not defined $self) {
355
            # not in memcached yet
356
            $self = read_config_file($conf_fname);
357
        }
358
    } else {
359
        # non-memcached env, read from file
360
        $self = read_config_file($conf_fname);
361
    }
362
369
363
    $self->{"config_file"} = $conf_fname;
370
    $self->{"config_file"} = $conf_fname;
364
    warn "read_config_file($conf_fname) returned undef" if !defined($self->{"config"});
371
    $self->{"namespace"} = $namespace;
365
    return if !defined($self->{"config"});
366
372
367
    $self->{"Zconn"} = undef;    # Zebra Connections
373
    $self->{"Zconn"} = undef;    # Zebra Connections
368
    $self->{"marcfromkohafield"} = undef; # the hash with relations between koha table fields and MARC field/subfield
374
    $self->{"marcfromkohafield"} = undef; # the hash with relations between koha table fields and MARC field/subfield
Lines 379-385 sub new { Link Here
379
385
380
=head2 set_context
386
=head2 set_context
381
387
382
  $context = new C4::Context;
383
  $context->set_context();
388
  $context->set_context();
384
or
389
or
385
  set_context C4::Context $context;
390
  set_context C4::Context $context;
Lines 409-421 sub set_context Link Here
409
    # break this assumption by playing silly buggers, but that's
414
    # break this assumption by playing silly buggers, but that's
410
    # harder to do than doing it properly, and harder to check
415
    # harder to do than doing it properly, and harder to check
411
    # for.
416
    # for.
417
    my $schema;
412
    if (ref($self) eq "")
418
    if (ref($self) eq "")
413
    {
419
    {
414
        # Class method. The new context is the next argument.
420
        # Class method. The new context is the next argument.
415
        $new_context = shift;
421
        $new_context = shift or croak "No new context";
422
        $schema = Koha::Database->new_schema($new_context);
416
    } else {
423
    } else {
417
        # Instance method. The new context is $self.
424
        # Instance method. The new context is $self.
418
        $new_context = $self;
425
        $new_context = $self;
426
427
        # undef $self->{schema} if $self->{schema} && !$self->{schema}->ping
428
        $schema = $self->{schema} ||= Koha::Database->new_schema($self);
419
    }
429
    }
420
430
421
    # Save the old context, if any, on the stack
431
    # Save the old context, if any, on the stack
Lines 423-428 sub set_context Link Here
423
433
424
    # Set the new context
434
    # Set the new context
425
    $context = $new_context;
435
    $context = $new_context;
436
    Koha::Database->set_schema($schema);
426
}
437
}
427
438
428
=head2 restore_context
439
=head2 restore_context
Lines 438-456 sub restore_context Link Here
438
{
449
{
439
    my $self = shift;
450
    my $self = shift;
440
451
441
    if ($#context_stack < 0)
442
    {
443
        # Stack underflow.
444
        die "Context stack underflow";
445
    }
446
447
    # Pop the old context and set it.
452
    # Pop the old context and set it.
448
    $context = pop @context_stack;
453
    $context = pop @context_stack;
454
    Koha::Database->restore_schema();
449
455
450
    # FIXME - Should this return something, like maybe the context
456
    # FIXME - Should this return something, like maybe the context
451
    # that was current when this was called?
457
    # that was current when this was called?
452
}
458
}
453
459
460
=head2 run_within_context
461
462
  $context->run_within_context(sub {...});
463
464
Runs code within context
465
466
=cut
467
468
#'
469
sub run_within_context
470
{
471
    my $self = shift;
472
    my $code = shift or croak "No code";
473
474
    $self->set_context;
475
476
    local $@;
477
    my $ret = eval { $code->(@_) };
478
    my $died = $@;
479
    $self->restore_context;
480
    die $died if $died;
481
    return $ret;
482
}
483
454
=head2 config
484
=head2 config
455
485
456
  $value = C4::Context->config("config_variable");
486
  $value = C4::Context->config("config_variable");
Lines 467-492 C<C4::Config-E<gt>new> will not return it. Link Here
467
=cut
497
=cut
468
498
469
sub _common_config {
499
sub _common_config {
470
	my $var = shift;
500
    my $self = shift;
471
	my $term = shift;
501
    my $var = shift;
472
    return if !defined($context->{$term});
502
    my $term = shift;
503
504
    $self = $context unless ref $self;
505
    return if !defined($self->{$term});
473
       # Presumably $self->{$term} might be
506
       # Presumably $self->{$term} might be
474
       # undefined if the config file given to &new
507
       # undefined if the config file given to &new
475
       # didn't exist, and the caller didn't bother
508
       # didn't exist, and the caller didn't bother
476
       # to check the return value.
509
       # to check the return value.
477
510
478
    # Return the value of the requested config variable
511
    # Return the value of the requested config variable
479
    return $context->{$term}->{$var};
512
    return $self->{$term}->{$var};
480
}
513
}
481
514
482
sub config {
515
sub config {
483
	return _common_config($_[1],'config');
516
    my $self = shift;
517
    return $self->_common_config($_[0],'config');
484
}
518
}
485
sub zebraconfig {
519
sub zebraconfig {
486
	return _common_config($_[1],'server');
520
    my $self = shift;
521
    return $self->_common_config($_[0],'server');
487
}
522
}
488
sub ModZebrations {
523
sub ModZebrations {
489
	return _common_config($_[1],'serverinfo');
524
    my $self = shift;
525
    return $self->_common_config($_[0],'serverinfo');
490
}
526
}
491
527
492
=head2 preference
528
=head2 preference
Lines 685-691 sub delete_preference { Link Here
685
721
686
Returns a connection to the Zebra database
722
Returns a connection to the Zebra database
687
723
688
C<$self> 
724
C<$self>
689
725
690
C<$server> one of the servers defined in the koha-conf.xml file
726
C<$server> one of the servers defined in the koha-conf.xml file
691
727
Lines 796-803 creates one, and connects to the database. Link Here
796
832
797
This database handle is cached for future use: if you call
833
This database handle is cached for future use: if you call
798
C<C4::Context-E<gt>dbh> twice, you will get the same handle both
834
C<C4::Context-E<gt>dbh> twice, you will get the same handle both
799
times. If you need a second database handle, use C<&new_dbh> and
835
times. If you need a second database handle, use C<&new_dbh>.
800
possibly C<&set_dbh>.
801
836
802
=cut
837
=cut
803
838
Lines 836-899 sub new_dbh Link Here
836
    return &dbh({ new => 1 });
871
    return &dbh({ new => 1 });
837
}
872
}
838
873
839
=head2 set_dbh
840
841
  $my_dbh = C4::Connect->new_dbh;
842
  C4::Connect->set_dbh($my_dbh);
843
  ...
844
  C4::Connect->restore_dbh;
845
846
C<&set_dbh> and C<&restore_dbh> work in a manner analogous to
847
C<&set_context> and C<&restore_context>.
848
849
C<&set_dbh> saves the current database handle on a stack, then sets
850
the current database handle to C<$my_dbh>.
851
852
C<$my_dbh> is assumed to be a good database handle.
853
854
=cut
855
856
#'
857
sub set_dbh
858
{
859
    my $self = shift;
860
    my $new_dbh = shift;
861
862
    # Save the current database handle on the handle stack.
863
    # We assume that $new_dbh is all good: if the caller wants to
864
    # screw himself by passing an invalid handle, that's fine by
865
    # us.
866
    push @{$context->{"dbh_stack"}}, $context->{"dbh"};
867
    $context->{"dbh"} = $new_dbh;
868
}
869
870
=head2 restore_dbh
871
872
  C4::Context->restore_dbh;
873
874
Restores the database handle saved by an earlier call to
875
C<C4::Context-E<gt>set_dbh>.
876
877
=cut
878
879
#'
880
sub restore_dbh
881
{
882
    my $self = shift;
883
884
    if ($#{$context->{"dbh_stack"}} < 0)
885
    {
886
        # Stack underflow
887
        die "DBH stack underflow";
888
    }
889
890
    # Pop the old database handle and set it.
891
    $context->{"dbh"} = pop @{$context->{"dbh_stack"}};
892
893
    # FIXME - If it is determined that restore_context should
894
    # return something, then this function should, too.
895
}
896
897
=head2 queryparser
874
=head2 queryparser
898
875
899
  $queryparser = C4::Context->queryparser
876
  $queryparser = C4::Context->queryparser
(-)a/Koha/Database.pm (-8 / +30 lines)
Lines 46-57 __PACKAGE__->mk_accessors(qw( )); Link Here
46
# database connection from the data given in the current context, and
46
# database connection from the data given in the current context, and
47
# returns it.
47
# returns it.
48
sub _new_schema {
48
sub _new_schema {
49
    my $context = shift || C4::Context->current();
49
50
50
    require Koha::Schema;
51
    require Koha::Schema;
51
52
52
    my $context = C4::Context->new();
53
    my $db_driver = $context->db_driver;
53
54
    my $db_driver = $context->{db_driver};
55
54
56
    my $db_name   = $context->config("database");
55
    my $db_name   = $context->config("database");
57
    my $db_host   = $context->config("hostname");
56
    my $db_host   = $context->config("hostname");
Lines 123-138 sub schema { Link Here
123
        return $database->{schema} if defined $database->{schema};
122
        return $database->{schema} if defined $database->{schema};
124
    }
123
    }
125
124
126
    $database->{schema} = &_new_schema();
125
    $database->{schema} = &_new_schema($params->{context});
127
    return $database->{schema};
126
    return $database->{schema};
128
}
127
}
129
128
130
=head2 new_schema
129
=head2 new_schema
131
130
132
  $schema = $database->new_schema;
131
  $schema = $database->new_schema($context);
133
132
134
Creates a new connection to the Koha database for the current context,
133
Creates a new connection to the Koha database for the context
135
and returns the database handle (a C<DBI::db> object).
134
(current is default), and returns the database handle (a C<DBI::db> object).
136
135
137
The handle is not saved anywhere: this method is strictly a
136
The handle is not saved anywhere: this method is strictly a
138
convenience function; the point is that it knows which database to
137
convenience function; the point is that it knows which database to
Lines 144-150 connect to so that the caller doesn't have to know. Link Here
144
sub new_schema {
143
sub new_schema {
145
    my $self = shift;
144
    my $self = shift;
146
145
147
    return &_new_schema();
146
    return &_new_schema(@_);
148
}
147
}
149
148
150
=head2 set_schema
149
=head2 set_schema
Lines 201-206 sub restore_schema { Link Here
201
    # return something, then this function should, too.
200
    # return something, then this function should, too.
202
}
201
}
203
202
203
=head2 run_with_schema
204
205
  $database->run_with_schema( $schema, sub {...} );
206
207
Restores the database handle saved by an earlier call to
208
C<$database-E<gt>set_schema> C<$database-E<gt>restore_schema> wrapper.
209
210
=cut
211
212
sub run_with_schema {
213
    my $self = shift;
214
    my $schema = shift or croak "No schema";
215
    my $code = shift or croak "No sub";
216
217
    $self->set_schema;
218
    local $@;
219
    my $ret = eval { $code->(@_) };
220
    my $died = $@;
221
    $self->restore_schema;
222
    die $died if $died;
223
    return $ret;
224
}
225
204
=head2 EXPORT
226
=head2 EXPORT
205
227
206
None by default.
228
None by default.
(-)a/Koha/Handler/Plack.pm (+163 lines)
Line 0 Link Here
1
package Koha::Handler::Plack;
2
3
# Copyright (c) 2016 Catalyst IT
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along with
17
# Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
=head1 NAME
21
22
  Koha::Handler::Plack - Plack helper
23
24
=head1 SYNOPSIS
25
26
  koha.psgi:
27
  use Koha::Handler::Plack;
28
29
  my %HOST_CONF = (
30
      'koha1.com' => { ...  },
31
      'koha2.com' => { ...  },
32
      ...
33
  );
34
  # last line
35
  Koha::Handler::Plack->app_per_host(\%HOST_CONF);
36
37
  See C<app_per_host()> below
38
39
=head1 DESCRIPTION
40
41
  Some handy function to help with Koha/Plack in a multi-host situation.
42
43
  The problem:
44
  Koha app relies on env vars. This should be changed, ie C4::Context should
45
  be upgraded to Koha::App, but until then we need a gap filler. That's
46
  because once up, there's no way to pass on new env to a psgi container.
47
  In Apache, for instance, we can specify env vars per virtual host. Plack
48
  has no such concept.
49
50
  Solution:
51
  We need to modify the environment in situ, per virtual host - app_per_host().
52
  We specify env for each hostname, and apply.
53
54
=cut
55
56
use Modern::Perl;
57
use Carp;
58
59
use Plack::Builder;
60
61
=head1 CLASS METHODS
62
63
=head2 app_per_host($host_apps)
64
65
  App wrapper for per virtual host scenario.
66
67
  C<$host_apps>:
68
      {
69
          hostname => 'koha1.com',
70
          app => $app1,
71
          context => $context1,
72
      },
73
      {
74
          hostname => ['koha2.com', 'www.koha2.com'],
75
          app => $app2,
76
          context => $context2,
77
      },
78
      ...
79
80
  C<hostname> is mandatory.
81
82
  koha.psgi:
83
84
  use Plack::Builder;
85
  use Plack::App::CGIBin;
86
87
  use C4::Context;
88
89
  my $opac_app = builder {
90
      enable "Plack::Middleware::Static",
91
              path => qr{^/opac-tmpl/}, root => '/usr/share/koha/opac/htdocs/';
92
93
      enable 'StackTrace';
94
      mount "/cgi-bin/koha" => Plack::App::CGIBin->new(root => "/usr/share/koha/opac/cgi-bin/opac");
95
  };
96
  my $intranet_app = builder {
97
      enable "Plack::Middleware::Static",
98
              path => qr{^/intranet-tmpl/}, root => '/usr/share/koha/intranet/htdocs/';
99
100
      enable 'StackTrace';
101
      mount "/cgi-bin/koha" => Plack::App::CGIBin->new(root => "/usr/share/koha/cgi-bin");
102
  };
103
104
  my @host_def;
105
106
  my $conf_file_1 = "/etc/koha/site-1/koha_conf.xml";
107
  my $context_1 = C4::Context->new($conf_file_1);
108
  push @host_def,
109
      {
110
          hostname => [ "public.host.for.site-1", "www.public.host.for.site-1" ],
111
          app => $opac_app,
112
          context => $context_1,
113
      },
114
      {
115
          hostname => "intranet.host.for.site-1",
116
          app => $intranet_app,
117
          context => $context_1,
118
      };
119
120
  my $conf_file_2 = "/etc/koha/site-1/koha_conf.xml";
121
  my $context_2 = C4::Context->new($conf_file_2);
122
  push @host_def,
123
      {
124
          hostname => "public.host.for.site-2",
125
          app => $opac_app,
126
          context => $context_2,
127
      },
128
      {
129
          hostname => "intranet.host.for.site-2",
130
          app => $intranet_app,
131
          context => $context_2,
132
      };
133
134
  ...
135
136
  Koha::Handler::Plack->app_per_host( \@host_def );
137
138
=cut
139
140
sub app_per_host {
141
    my $class = shift;
142
    my $sites = shift or die "No sites spec";
143
144
    my $builder = Plack::Builder->new;
145
    foreach my $site_params ( @$sites ) {
146
        my $hosts = $site_params->{hostname} or croak "No hostname";
147
        $hosts = [$hosts] unless ref $hosts;
148
149
        my $app = $site_params->{app} or croak "No app";
150
        my $context = $site_params->{context} or croak "No Koha Context";
151
152
        foreach my $host (@$hosts) {
153
            $builder->mount("http://$host/" => sub {
154
                my $env = shift;
155
156
                return $context->run_within_context(sub { $app->($env) });
157
            });
158
        }
159
    }
160
    return $builder->to_app;
161
}
162
163
1;
(-)a/Koha/Handler/Plack/CGI.pm (+228 lines)
Line 0 Link Here
1
package Koha::Handler::Plack::CGI;
2
3
# Copyright (c) 2016 Catalyst IT
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along with
17
# Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
=head1 NAME
21
22
  Koha::Handler::Plack::CGI - Plack helper for CGI scripts
23
24
=head1 SYNOPSIS
25
26
  koha.psgi:
27
  use Koha::Handler::Plack::CGI;
28
29
  my %koha_env = (
30
      opac => {
31
          static_root => '/usr/share/koha/opac/htdocs',
32
          script_root => '/usr/share/koha/opac',
33
      },
34
      intranet => {
35
          static_root => '/usr/share/koha/intranet/htdocs',
36
          script_root => '/usr/share/koha/intranet'
37
      }
38
  );
39
  my @sites = (
40
      {
41
          opac_hostname => 'koha1-opac.com',
42
          intranet_hostname => 'koha1-intranet.com',
43
          config = '/etc/koha/koha1/koha-conf.xml'
44
      },
45
      {
46
          opac_hostname => ['opac.koha2.com', 'www.opackoha2.com'],
47
          intranet_hostname => ['intranet.koha2.com', 'www.intranetkoha2.com'],
48
          config = '/etc/koha/koha2/koha-conf.xml'
49
      },
50
  );
51
52
  # last line
53
  Koha::Handler::Plack::CGI->app_per_host(\%HOST_CONF);
54
55
  See C<app_per_host()> below
56
57
=head1 DESCRIPTION
58
59
  CGI script runner.
60
61
  One beautiful day wiwill move away from that and have proper App module
62
  with router and handlers</dream>
63
64
  See C<Koha::Handler::Plack>
65
66
=cut
67
68
use Modern::Perl;
69
use Carp;
70
71
use Plack::Builder;
72
use Plack::App::CGIBin;
73
74
use parent "Koha::Handler::Plack";
75
76
use C4::Context;
77
78
=head1 CLASS METHODS
79
80
=head2 app($context, $env)
81
82
  Plack app builder fora CGI app
83
84
  C<$context>: "opac" or "intranet"
85
  C<$env>:
86
      {
87
          static_root => '...',
88
          script_root => '...',
89
          pugins => [
90
              [ 'StackTrace' ],
91
              ...
92
          ],
93
      }
94
95
  koha.psgi:
96
97
  Koha::Handler::Plack::CGI->app( "opac", \%opac_app_env );
98
99
=cut
100
101
sub app {
102
    my $class = shift;
103
    my $context = shift;
104
    croak "Invalid app context '$context' - must be 'opac' or 'intranet'"
105
      unless $context =~ m/^(opac|intranet)$/;
106
    my $env = shift or croak "No $context env details";
107
108
    my $static_root = $env->{static_root} or croak "No $context static_root";
109
    $static_root = "$static_root/" unless $static_root =~ m!/$!;
110
    my $script_root = $env->{script_root} or croak "No $context script_root";
111
    $script_root =~ s!/$!!;
112
    my $plugins = $env->{plugins} || [];
113
    my $is_intranet = $context eq "intranet";
114
115
    builder {
116
        enable "Plack::Middleware::Static",
117
                path => qr{^/$context-tmpl/}, root => $static_root;
118
119
        map enable(@$_), @$plugins;
120
121
        mount "/cgi-bin/koha" => Plack::App::CGIBin->new(root => $script_root)->to_app;
122
        mount "/" => sub {
123
            return [ 302, [ Location => '/cgi-bin/koha/' . ( $is_intranet ? 'mainpage.pl' : 'opac-main.pl' ) ], [] ];
124
        };
125
    };
126
}
127
128
=head2 multi_site($env, $sites)
129
130
  App wrapper for per virtual host scenario.
131
132
  C<$env>:
133
      {
134
          opac => {
135
              static_root => '/usr/share/koha/opac/htdocs',
136
              script_root => '/usr/share/koha/opac/cgi-bin/opac',
137
              pugins => [
138
                  [ 'StackTrace' ],
139
              ],
140
          },
141
          intranet => {
142
              static_root => '/usr/share/koha/intranet/htdocs',
143
              script_root => '/usr/share/koha/cgi-bin'
144
          }
145
      }
146
  C<$sites>:
147
      {
148
          namespace => 'koha1',
149
          opac_hostname => 'koha1-opac.com',
150
          intranet_hostname => 'koha1-intranet.com',
151
          config => '/etc/koha/sites/koha1/koha-conf.xml',
152
          shared_config => 1
153
      },
154
      {
155
          namespace => 'koha2',
156
          opac_hostname => ['opac.koha2.com', 'www.opackoha2.com'],
157
          intranet_hostname => ['intranet.koha2.com', 'www.intranetkoha2.com'],
158
          config => '/etc/koha/sites/koha2/koha-conf.xml'
159
      },
160
      ...
161
162
  koha.psgi:
163
164
  Koha::Handler::Plack::CGI->multi_site( \%koha_app_env, \@sites );
165
166
=cut
167
168
my $DUMMY_KOHA_CONF = "<yazgfs><config>DUMMY</config></yazgfs>";
169
sub multi_site {
170
    my $class = shift;
171
    my $env = shift or croak "No Koha env details";
172
    my $sites = shift or croak "No sites spec";
173
174
    my ($opac_app, $intranet_app);
175
176
    if (my $opac = $env->{opac}) {
177
        $opac_app = $class->app('opac', $opac);
178
    }
179
180
    if (my $intranet = $env->{intranet}) {
181
        $intranet_app = $class->app('intranet', $intranet);
182
    }
183
184
    my @host_def = map {
185
        my $namespace      = $_->{namespace} or croak "No namespace";
186
        my $config         = $_->{config}    or croak "Site without config";
187
        my $shared_context = $_->{shared_context};
188
189
        my $context = C4::Context->new($config, $namespace);
190
191
        my @hd;
192
        if (my $hostname = $_->{opac_hostname}) {
193
            croak "You have OPAC hosts without OPAC env details" unless $opac_app;
194
            push @hd, {
195
                hostname => $hostname,
196
                app => sub {
197
                    # XXX this may need some rethinking
198
                    local $ENV{KOHA_CONF} = \$DUMMY_KOHA_CONF;
199
                    local $ENV{MEMCACHED_NAMESPACE} = $namespace;
200
201
                    $opac_app->(@_);
202
                },
203
                context => $context,
204
                shared_context => $shared_context,
205
            };
206
        }
207
        if (my $hostname = $_->{intranet_hostname}) {
208
            croak "You have Intranet hosts without Intranet env details" unless $intranet_app;
209
            push @hd, {
210
                hostname => $hostname,
211
                app => sub {
212
                    # XXX this may need some rethinking
213
                    local $ENV{KOHA_CONF} = \$DUMMY_KOHA_CONF;
214
                    local $ENV{MEMCACHED_NAMESPACE} = $namespace;
215
216
                    $intranet_app->(@_);
217
                },
218
                context => $context,
219
                shared_context => $shared_context,
220
            };
221
        }
222
        @hd;
223
    } @$sites;
224
225
    return $class->app_per_host( \@host_def );
226
}
227
228
1;
(-)a/admin/systempreferences.pl (-1 / +1 lines)
Lines 387-393 output_html_with_http_headers $input, $cookie, $template->output; Link Here
387
# .pref files.
387
# .pref files.
388
388
389
sub get_prefs_from_files {
389
sub get_prefs_from_files {
390
    my $context       = C4::Context->new();
390
    my $context       = C4::Context->current();
391
    my $path_pref_en  = $context->config('intrahtdocs') .
391
    my $path_pref_en  = $context->config('intrahtdocs') .
392
                        '/prog/en/modules/admin/preferences';
392
                        '/prog/en/modules/admin/preferences';
393
    # Get all .pref file names
393
    # Get all .pref file names
(-)a/misc/cronjobs/check-url.pl (-1 / +1 lines)
Lines 190-196 sub check_all_url { Link Here
190
    my $checker = C4::URL::Checker->new($timeout,$agent);
190
    my $checker = C4::URL::Checker->new($timeout,$agent);
191
    $checker->{ host_default }  = $host;
191
    $checker->{ host_default }  = $host;
192
    
192
    
193
    my $context = new C4::Context(  );  
193
    my $context = C4::Context->current();
194
    my $dbh = $context->dbh;
194
    my $dbh = $context->dbh;
195
    my $sth = $dbh->prepare( 
195
    my $sth = $dbh->prepare( 
196
        "SELECT biblionumber FROM biblioitems WHERE url <> ''" );
196
        "SELECT biblionumber FROM biblioitems WHERE url <> ''" );
(-)a/misc/plack/koha-multi.psgi (+29 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# This is a minimal example. You can include all frills from koha.psgi
4
# To try it:
5
# plackup -I /usr/share/koha/lib --port 5010 koha-multi.psgi
6
7
my %KOHA_ENV = (
8
  opac => {
9
      static_root => '/usr/share/koha/opac/htdocs',
10
      script_root => '/usr/share/koha/opac/cgi-bin/opac',
11
      pugins => [
12
	# don't enable this plugin in production, since stack traces reveal too much information
13
	# about system to potential attackers!
14
          [ 'StackTrace' ],
15
      ],
16
  },
17
  intranet => {
18
      static_root => '/usr/share/koha/intranet/htdocs',
19
      script_root => '/usr/share/koha/intranet/cgi-bin',
20
  }
21
);
22
my @SITES = map {
23
    namespace => $_,
24
    opac_hostname => "opac.$_.my-koha-multisite.net",
25
    intranet_hostname => "intranet.$_.my-koha-multisite.net",
26
    config => "/etc/koha/sites/$_/koha-conf.xml"
27
}, qw(koha1 koha2 koha3);
28
29
Koha::Handler::Plack::CGI->multi_site( \%KOHA_ENV, \@SITES );
(-)a/misc/translator/LangInstaller.pm (-2 / +2 lines)
Lines 56-62 sub new { Link Here
56
56
57
    my $self                 = { };
57
    my $self                 = { };
58
58
59
    my $context              = C4::Context->new();
59
    my $context              = C4::Context->current();
60
    $self->{context}         = $context;
60
    $self->{context}         = $context;
61
    $self->{path_pref_en}    = $context->config('intrahtdocs') .
61
    $self->{path_pref_en}    = $context->config('intrahtdocs') .
62
                               '/prog/en/modules/admin/preferences';
62
                               '/prog/en/modules/admin/preferences';
Lines 140-146 sub new { Link Here
140
sub po_filename {
140
sub po_filename {
141
    my $self = shift;
141
    my $self = shift;
142
142
143
    my $context    = C4::Context->new;
143
    my $context    = C4::Context->current();
144
    my $trans_path = $Bin . '/po';
144
    my $trans_path = $Bin . '/po';
145
    my $trans_file = "$trans_path/" . $self->{lang} . "-pref.po";
145
    my $trans_file = "$trans_path/" . $self->{lang} . "-pref.po";
146
    return $trans_file;
146
    return $trans_file;
(-)a/t/Koha_Handler_Plack.t (+136 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use Test::More tests => 15;
4
use Plack::Test;
5
use Plack::Test::MockHTTP;
6
use Test::Mock::LWP::Dispatch;
7
use Test::MockModule;
8
use HTTP::Request::Common;
9
use FindBin qw($Bin);
10
use Data::Dumper;
11
12
use_ok("Koha::Handler::Plack");
13
use_ok("Koha::Handler::Plack::CGI");
14
15
use C4::Context;
16
17
my $db = Test::MockModule->new('Koha::Database');
18
$db->mock(
19
    _new_schema => sub {
20
        return $_[0];
21
    }
22
);
23
24
sub make_response {
25
    return join ";", map defined($_) ? $_ : "", @_;
26
}
27
sub dummy_val {
28
    return C4::Context->config("dummy");
29
}
30
sub check_context {
31
    my $dummy_val = dummy_val();
32
    is $dummy_val, undef, "context preserved"
33
      or diag("dummy val: $dummy_val");
34
}
35
36
my $app = sub {
37
    return [
38
        200,
39
        [ 'Content-Type' => 'text/plain' ],
40
        [ make_response(dummy_val()) ]
41
    ];
42
};
43
my $generic_url = "http://dummyhost.com/";
44
45
my $KOHA_CONF_XML = <<EOS;
46
<yazgfs>
47
    <config>
48
        <kohasite>test</kohasite>
49
        <dummy>XML</dummy>
50
        <intrahtdocs>.</intrahtdocs>
51
    </config>
52
</yazgfs>
53
EOS
54
55
my @HOST_CONF = (
56
    {
57
        hostname => ['koha-file.com', 'www.koha-file.com'],
58
        app => $app,
59
        context => C4::Context->new("$Bin/conf/koha1/koha-conf.xml"),
60
        _dummy => "KOHA1"
61
    },
62
    {
63
        hostname => ['koha-xml.com', 'www.koha-xml.com'],
64
        app => $app,
65
        context => C4::Context->new(\$KOHA_CONF_XML),
66
        _dummy => "XML"
67
    },
68
);
69
test_psgi
70
    app => Koha::Handler::Plack->app_per_host(\@HOST_CONF),
71
    client => sub {
72
        my $cb  = shift;
73
74
        foreach my $site_params ( @HOST_CONF ) {
75
            my $valid_response = make_response(
76
                $site_params->{_dummy}
77
            );
78
            foreach (@{$site_params->{hostname}}) {
79
                my $res = $cb->(GET "http://$_/");
80
                is $res->content, $valid_response, $_
81
                  or diag(Dumper($site_params, $_, $res->as_string));
82
                check_context();
83
            }
84
        }
85
86
        $res = $cb->(GET $generic_url);
87
        is $res->code, 404, "app_per_host unknown host"
88
          or diag($res->as_string);
89
    };
90
91
my %MULTI_HOST_ENV = (
92
    opac => {
93
        static_root => "$Bin/../koha-tmpl/opac-tmpl/bootstrap",
94
        script_root => "$Bin/../opac",
95
    },
96
    intranet => {
97
        static_root => "$Bin/../koha-tmpl/intranet-tmpl/bootstrap",
98
        script_root => "$Bin/.."
99
    }
100
);
101
my @MULTI_HOST_SITES = (
102
    {
103
        namespace => 'koha1',
104
        opac_hostname => ['opac.koha1.com', 'www.opac.koha1.com'],
105
        intranet_hostname => ['intranet.koha1.com', 'www.intranet.koha1.com'],
106
        config => "$Bin/conf/koha1/koha-conf.xml",
107
    },
108
    {
109
        namespace => 'koha2',
110
        opac_hostname => ['opac.koha2.com', 'www.opac.koha2.com'],
111
        intranet_hostname => ['intranet.koha2.com', 'www.intranet.koha2.com'],
112
        config => "$Bin/conf/koha2/koha-conf.xml",
113
        shared_context => 1,
114
    },
115
);
116
test_psgi
117
    app => Koha::Handler::Plack::CGI->multi_site(\%MULTI_HOST_ENV, \@MULTI_HOST_SITES),
118
    client => sub {
119
        my $cb  = shift;
120
121
        foreach my $site (@MULTI_HOST_SITES) {
122
            my $opac = $site->{opac_hostname};
123
            foreach my $host (@$opac) {
124
# this is not really a test, but cannot do any better atm
125
# TODO: a complex test involving two database connections
126
                my $res = $cb->(GET "http://$host/");
127
                # A future implementation may not redirect
128
                if ($res->is_redirect) {
129
                    my $loc = $res->header("Location");
130
                    $res = $cb->(GET "http://$host$loc");
131
                }
132
                is $res->code, 500, "multi_site() $host"
133
                  or diag($res->as_string);
134
            }
135
        }
136
    };
(-)a/t/conf/dummy/koha-conf.xml (+7 lines)
Line 0 Link Here
1
<yazgfs>
2
    <config>
3
        <kohasite>dummy</kohasite>
4
        <dummy>DUMMY</dummy>
5
        <intrahtdocs>.</intrahtdocs>
6
    </config>
7
</yazgfs>
(-)a/t/conf/koha1/koha-conf.xml (+7 lines)
Line 0 Link Here
1
<yazgfs>
2
    <config>
3
        <kohasite>koha1</kohasite>
4
        <dummy>KOHA1</dummy>
5
        <intrahtdocs>.</intrahtdocs>
6
    </config>
7
</yazgfs>
(-)a/t/conf/koha2/koha-conf.xml (+5 lines)
Line 0 Link Here
1
<yazgfs>
2
    <config>
3
        <dummy>KOHA2</dummy>
4
    </config>
5
</yazgfs>
(-)a/t/db_dependent/Amazon.t (-1 / +1 lines)
Lines 14-20 BEGIN { Link Here
14
    use_ok('C4::External::Amazon');
14
    use_ok('C4::External::Amazon');
15
}
15
}
16
16
17
my $context = C4::Context->new();
17
my $context = C4::Context->current();
18
18
19
my $locale = $context->preference('AmazonLocale');
19
my $locale = $context->preference('AmazonLocale');
20
20
(-)a/t/db_dependent/Context.t (-1 / +1 lines)
Lines 47-53 C4::Context->clear_syspref_cache(); Link Here
47
C4::Context->enable_syspref_cache();
47
C4::Context->enable_syspref_cache();
48
$dbh->rollback;
48
$dbh->rollback;
49
49
50
ok($koha = C4::Context->new,  'C4::Context->new');
50
ok($koha = C4::Context->current,  'C4::Context->current');
51
my @keys = keys %$koha;
51
my @keys = keys %$koha;
52
my $width = 0;
52
my $width = 0;
53
if (ok(@keys)) { 
53
if (ok(@keys)) { 
(-)a/t/db_dependent/Koha_template_plugin_KohaDates.t (-1 / +1 lines)
Lines 14-20 BEGIN { Link Here
14
my $module_context = new Test::MockModule('C4::Context');
14
my $module_context = new Test::MockModule('C4::Context');
15
15
16
my $date = "1973-05-21";
16
my $date = "1973-05-21";
17
my $context = C4::Context->new();
17
my $context = C4::Context->current();
18
18
19
my $filter = Koha::Template::Plugin::KohaDates->new();
19
my $filter = Koha::Template::Plugin::KohaDates->new();
20
ok ($filter, "new()");
20
ok ($filter, "new()");
(-)a/t/db_dependent/XISBN.t (-1 / +1 lines)
Lines 26-32 my $search_module = new Test::MockModule('C4::Search'); Link Here
26
26
27
$search_module->mock('SimpleSearch', \&Mock_SimpleSearch );
27
$search_module->mock('SimpleSearch', \&Mock_SimpleSearch );
28
28
29
my $context = C4::Context->new;
29
my $context = C4::Context->current;
30
30
31
my ( $biblionumber_tag, $biblionumber_subfield ) =
31
my ( $biblionumber_tag, $biblionumber_subfield ) =
32
  GetMarcFromKohaField( 'biblio.biblionumber', '' );
32
  GetMarcFromKohaField( 'biblio.biblionumber', '' );
(-)a/t/db_dependent/sysprefs.t (-3 / +3 lines)
Lines 62-71 is(C4::Context->preference('testpreference'), undef, 'clearing preference cache' Link Here
62
62
63
delete $ENV{OVERRIDE_SYSPREF_opacheader};
63
delete $ENV{OVERRIDE_SYSPREF_opacheader};
64
64
65
my $context1 = C4::Context->new();
65
my $DUMMY_KOHA_CONF = "<yazgfs><config><dummy>DUMMY</dummy></config></yazgfs>";
66
my $context1 = C4::Context->new($DUMMY_KOHA_CONF);
66
is( $context1->preference('opacheader'), $opacheader, 'context1 "opacheader"');
67
is( $context1->preference('opacheader'), $opacheader, 'context1 "opacheader"');
67
68
68
my $context2 = C4::Context->new();
69
my $context2 = C4::Context->new($DUMMY_KOHA_CONF);
69
$context2->set_preference( 'opacheader', $newopacheader );
70
$context2->set_preference( 'opacheader', $newopacheader );
70
is( $context1->preference('opacheader'), $opacheader, 'context1 "opacheader"');
71
is( $context1->preference('opacheader'), $opacheader, 'context1 "opacheader"');
71
is( $context2->preference('opacheader'), $newopacheader, 'context2 "opacheader"');
72
is( $context2->preference('opacheader'), $newopacheader, 'context2 "opacheader"');
72
- 

Return to bug 15562