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

(-)a/C4/Context.pm (-2 / +5 lines)
Lines 403-409 with this method. Link Here
403
403
404
=cut
404
=cut
405
405
406
my $syspref_cache = Koha::Caches->get_instance('syspref');
407
my $use_syspref_cache = 1;
406
my $use_syspref_cache = 1;
408
sub preference {
407
sub preference {
409
    my $self = shift;
408
    my $self = shift;
Lines 415-421 sub preference { Link Here
415
    $var = lc $var;
414
    $var = lc $var;
416
415
417
    if ($use_syspref_cache) {
416
    if ($use_syspref_cache) {
418
        $syspref_cache = Koha::Caches->get_instance('syspref') unless $syspref_cache;
417
        my $syspref_cache = Koha::Caches->get_instance('syspref');
419
        my $cached_var = $syspref_cache->get_from_cache("syspref_$var");
418
        my $cached_var = $syspref_cache->get_from_cache("syspref_$var");
420
        return $cached_var if defined $cached_var;
419
        return $cached_var if defined $cached_var;
421
    }
420
    }
Lines 425-430 sub preference { Link Here
425
    my $value = $syspref ? $syspref->value() : undef;
424
    my $value = $syspref ? $syspref->value() : undef;
426
425
427
    if ( $use_syspref_cache ) {
426
    if ( $use_syspref_cache ) {
427
        my $syspref_cache = Koha::Caches->get_instance('syspref');
428
        $syspref_cache->set_in_cache("syspref_$var", $value);
428
        $syspref_cache->set_in_cache("syspref_$var", $value);
429
    }
429
    }
430
    return $value;
430
    return $value;
Lines 480-485 will not be seen by this process. Link Here
480
480
481
sub clear_syspref_cache {
481
sub clear_syspref_cache {
482
    return unless $use_syspref_cache;
482
    return unless $use_syspref_cache;
483
    my $syspref_cache = Koha::Caches->get_instance('syspref');
483
    $syspref_cache->flush_all;
484
    $syspref_cache->flush_all;
484
}
485
}
485
486
Lines 533-538 sub set_preference { Link Here
533
    }
534
    }
534
535
535
    if ( $use_syspref_cache ) {
536
    if ( $use_syspref_cache ) {
537
        my $syspref_cache = Koha::Caches->get_instance('syspref');
536
        $syspref_cache->set_in_cache( "syspref_$variable", $value );
538
        $syspref_cache->set_in_cache( "syspref_$variable", $value );
537
    }
539
    }
538
540
Lines 554-559 sub delete_preference { Link Here
554
556
555
    if ( Koha::Config::SysPrefs->find( $var )->delete ) {
557
    if ( Koha::Config::SysPrefs->find( $var )->delete ) {
556
        if ( $use_syspref_cache ) {
558
        if ( $use_syspref_cache ) {
559
            my $syspref_cache = Koha::Caches->get_instance('syspref');
557
            $syspref_cache->clear_from_cache("syspref_$var");
560
            $syspref_cache->clear_from_cache("syspref_$var");
558
        }
561
        }
559
562
(-)a/Koha/App/Koha.pm (-2 / +50 lines)
Lines 7-12 use Mojo::Base 'Mojolicious'; Link Here
7
use Koha::Caches;
7
use Koha::Caches;
8
use Koha::Cache::Memory::Lite;
8
use Koha::Cache::Memory::Lite;
9
9
10
use C4::Context ();  # Do not call import
11
10
sub startup {
12
sub startup {
11
    my ($self) = @_;
13
    my ($self) = @_;
12
14
Lines 17-27 sub startup { Link Here
17
    # CGI::Compile
19
    # CGI::Compile
18
    $self->plugin('CGIBinKoha');
20
    $self->plugin('CGIBinKoha');
19
21
22
    # Plugin RESTV1 loads Koha::REST::V1 which loads C4::Context
23
    # This line make C4::Context::import return early to avoid warning about
24
    # config file not found
25
    # FIXME This is dirty...
26
    C4::Context->set_context({});
27
20
    # Create routes for API
28
    # Create routes for API
21
    # FIXME This generates routes like this: /api/api/v1/...
29
    # FIXME This generates routes like this: /api/api/v1/...
22
    $self->plugin('RESTV1');
30
    $self->plugin('RESTV1');
23
31
24
    $self->hook(before_dispatch => \&_before_dispatch);
32
    $self->hook(before_dispatch => \&_before_dispatch);
33
    $self->hook(around_action => \&_around_action);
25
34
26
    # Everything after this comment is only needed to use Mojolicious
35
    # Everything after this comment is only needed to use Mojolicious
27
    # controllers.
36
    # controllers.
Lines 55-63 sub _before_dispatch { Link Here
55
64
56
    $c->req->url->parse($url);
65
    $c->req->url->parse($url);
57
66
58
    # Flush caches before every request
67
}
59
    Koha::Caches->flush_L1_caches();
68
69
sub _around_action {
70
    my ($next, $c, $action, $last) = @_;
71
72
    # Flush memory caches before every request
73
    my $caches = $Koha::Caches::singleton_caches;
74
    if ($caches) {
75
        foreach my $key (keys %$caches) {
76
            my $cache = $caches->{$key};
77
            if (ref $cache->{cache} eq 'Cache::Memory') {
78
                $cache->flush_all;
79
            }
80
            $cache->flush_L1_cache;
81
        }
82
    }
83
    $Koha::Caches::singleton_caches = {};
60
    Koha::Cache::Memory::Lite->flush();
84
    Koha::Cache::Memory::Lite->flush();
85
86
    # Set KOHA_CONF
87
    my $previous_koha_conf = $ENV{KOHA_CONF};
88
    my $koha_conf = $c->req->headers->header('X-Koha-Conf');
89
    $ENV{KOHA_CONF} = $koha_conf if $koha_conf;
90
    unless ($ENV{KOHA_CONF}) {
91
        die "KOHA_CONF is not set. Either set the environment variable or use HTTP header X-Koha-Conf";
92
    }
93
94
    # Reload context and schema
95
    eval { C4::Context->restore_context; };
96
    C4::Context->set_context(C4::Context->new);
97
98
    eval { Koha::Database->restore_schema };
99
    Koha::Database->set_schema(Koha::Database->schema({new => 1}));
100
101
    my $ret = $next->();
102
103
    # Just in case the app receive requests with and without X-Koha-Conf
104
    # Requests without X-Koha-Conf shouldn't be affected by the latest request
105
    # with X-Koha-Conf
106
    $ENV{KOHA_CONF} = $previous_koha_conf;
107
108
    return $ret;
61
}
109
}
62
110
63
1;
111
1;
(-)a/Koha/App/Plugin/CGIBinKoha.pm (+2 lines)
Lines 78-83 sub _psgi_env { Link Here
78
        $env->{$name} = $value;
78
        $env->{$name} = $value;
79
    }
79
    }
80
80
81
    $env->{KOHA_CONF} = $c->req->headers->header('X-Koha-Conf') // $ENV{KOHA_CONF};
82
81
    return $env;
83
    return $env;
82
}
84
}
83
85
(-)a/etc/nginx.conf (-1 / +1 lines)
Lines 11-15 server { Link Here
11
    location / {
11
    location / {
12
        include proxy_params;
12
        include proxy_params;
13
        proxy_pass http://koha;
13
        proxy_pass http://koha;
14
        proxy_set_header X-Koha-Conf "/home/koha/etc/koha-conf.xml"; # CHANGEME
14
    }
15
    }
15
}
16
}
16
- 

Return to bug 20630