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

(-)a/misc/cronjobs/clear_report_cache.pl (-1 / +126 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use Getopt::Long;
6
use Pod::Usage;
7
8
use Koha::Cache;
9
10
my $help;
11
my $verbose;
12
my $report_id;
13
my $report_name;
14
my @sql_params;
15
my $type;
16
17
GetOptions(
18
    'i|id=s'     => \$report_id,
19
    'n|name=s'   => \$report_name,
20
    'p|param=s@' => \@sql_params,
21
    't|type=s'   => \$type,
22
    'h|help'     => \$help,
23
    'v|verbose'  => \$verbose,
24
);
25
26
pod2usage(1) if ( $help || !( $report_id || $report_name ) );
27
28
pod2usage(1) if ( $type && ( $type ne 'opac' && $type ne 'intranet' ) );
29
30
my $cache = Koha::Cache->get_instance();
31
32
if ( $cache->is_cache_active ) {
33
    my $key = "report:".($report_name ? "name:$report_name" : "id:$report_id") . join( '-', @sql_params );
34
35
36
    if ( !$type || $type eq 'opac' ) {
37
    	$cache->clear_from_cache("opac:$key");
38
        say "Cleared cached key 'opac:$key' for opac report " . $report_id || $report_name if $verbose;
39
    }
40
41
    if ( !$type || $type eq 'intranet' ) {
42
        $cache->clear_from_cache("intranet:$key");
43
        say "Cleared cached key 'intranet:$key' for intranet report " . $report_id || $report_name if $verbose;
44
    }
45
46
} else {
47
    say("Cache is not active");
48
}
49
=head1 NAME
50
51
clear_report_cache.pl - Clear the cached version of a public report
52
53
=head1 SYNOPSIS
54
55
clear_report_cache.pl [-i|--id] [-n|--name] [-p|--sql-params] [-t|--type] [-h|--help] [-v|--verbose]
56
57
This script will allow you to clear the cache for a given report even if it has not
58
yet reached its expiration time.
59
60
Make sure to set your memcached environment variable before running this script
61
62
export MEMCACHED_SERVERS="127.0.0.1:11211"
63
64
export MEMCACHED_NAMESPACE="koha_sitename"
65
66
=head1 OPTIONS
67
68
=over
69
70
=item B<-i|--id>
71
72
The id of the report to be cleared.
73
Either id or name must be specified.
74
75
=item B<-n|--name>
76
77
The name of the report to be cleared.
78
Either id or name must be specified.
79
80
=item B<-p|--param>
81
82
Repeatable. Specify a -p parameter for
83
each sql parameter you pass the report.
84
The order you specify them here should
85
match the order you specify when fetching
86
the report.
87
88
=item B<-t|--type>
89
90
Must be either 'opac' or 'intranet'.
91
92
Specifieds to only clear the cache for
93
the given report for the opac or intranet.
94
95
If not specified, both will be cleared.
96
97
=item B<-h|--help>
98
99
Print a brief help message
100
101
=item B<-v|--verbose>
102
103
Verbose mode.
104
105
=back
106
107
=head1 AUTHOR
108
109
Kyle M Hall <kyle@bywatersolutions.com>
110
111
=head1 COPYRIGHT
112
113
Copyright 2016 ByWater Solutions
114
115
=head1 LICENSE
116
117
This file is part of Koha.
118
119
Koha is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
120
Foundation; either version 3 of the License, or (at your option) any later version.
121
122
You should have received a copy of the GNU General Public License along
123
with Koha; if not, write to the Free Software Foundation, Inc.,
124
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
125
126
=cut

Return to bug 16650