Bug 13937: (follow-up) Pass through yaz switches and don't ignore case
[koha.git] / misc / z3950_responder.pl
1 #!/usr/bin/perl
2 #
3 # Copyright ByWater Solutions 2015
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 3 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
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 use Modern::Perl;
21
22 use Carp;
23 use Getopt::Long qw(:config no_ignore_case);
24 use Pod::Usage;
25
26 use C4::Context;
27 use Koha::Z3950Responder;
28
29 =head1 SYNOPSIS
30
31    z3950_responder.pl [-h|--help] [--man] [-a <pdufile>] [-v <loglevel>] [-l <logfile>] [-u <user>]
32                       [-c <config>] [-t <minutes>] [-k <kilobytes>] [-d <daemon>] [-p <pidfile>]
33                       [-C certfile] [-zKiDST1] [-m <time-format>] [-w <directory>] [--debug]
34                       [--add-item-status=SUBFIELD] [--prefetch=NUM_RECORDS]
35                       [<listener-addr>... ]
36
37 =head1 OPTIONS
38
39 =over 8
40
41 =item B<--help>
42
43 Prints a brief usage message and exits.
44
45 =item B<--man>
46
47 Displays manual page and exits.
48
49 =item B<--debug>
50
51 Turns on debug logging to the screen, and turns on single-process mode.
52
53 =item B<--add-item-status=SUBFIELD>
54
55 If given, adds item status information to the given subfield.
56
57 =item B<--add-status-multi-subfield>
58
59 With the above, instead of putting multiple item statuses in one subfield, adds a subfield for each
60 status string.
61
62 =item B<--prefetch=NUM_RECORDS>
63
64 Number of records to prefetch from Zebra. Defaults to 20.
65
66 =back
67
68 =head1 CONFIGURATION
69
70 The item status strings added by B<--add-item-status> can be configured with the B<Z3950_STATUS>
71 authorized value, using the following keys:
72
73 =over 4
74
75 =item AVAILABLE
76
77 =item CHECKED_OUT
78
79 =item LOST
80
81 =item NOT_FOR_LOAN
82
83 =item DAMAGED
84
85 =item WITHDRAWN
86
87 =item IN_TRANSIT
88
89 =item ON_HOLD
90
91 =back
92
93 =cut
94
95 my $add_item_status_subfield;
96 my $add_status_multi_subfield;
97 my $debug = 0;
98 my $help;
99 my $man;
100 my $prefetch = 20;
101 my @yaz_options;
102
103 sub add_yaz_option {
104     my ( $opt_name, $opt_value ) = @_;
105     warn "name: $opt_name and value: $opt_value";
106
107     push @yaz_options, "-$opt_name", "$opt_value";
108 }
109
110 sub pass_yaz_option {
111     my ( $opt_name ) = @_;
112
113     push @yaz_options, "-$opt_name";
114 }
115
116 GetOptions(
117     '-h|help' => \$help,
118     '--man' => \$man,
119     '--debug' => \$debug,
120     '--add-item-status=s' => \$add_item_status_subfield,
121     '--add-status-multi-subfield' => \$add_status_multi_subfield,
122     '--prefetch=i' => \$prefetch,
123     # Pass through YAZ options.
124     'a=s' => \&add_yaz_option,
125     'v=s' => \&add_yaz_option,
126     'l=s' => \&add_yaz_option,
127     'u=s' => \&add_yaz_option,
128     'c=s' => \&add_yaz_option,
129     't=s' => \&add_yaz_option,
130     'k=s' => \&add_yaz_option,
131     'd=s' => \&add_yaz_option,
132     'p=s' => \&add_yaz_option,
133     'C=s' => \&add_yaz_option,
134     'm=s' => \&add_yaz_option,
135     'w=s' => \&add_yaz_option,
136     'z' => \&pass_yaz_option,
137     'K' => \&pass_yaz_option,
138     'i' => \&pass_yaz_option,
139     'D' => \&pass_yaz_option,
140     'S' => \&pass_yaz_option,
141     'T' => \&pass_yaz_option,
142     '1' => \&pass_yaz_option
143 ) || pod2usage(2);
144
145 pod2usage(1) if $help;
146 pod2usage( -verbose => 2 ) if $man;
147
148 # Create and start the server.
149
150 die "This tool only works with Zebra" if C4::Context->preference('SearchEngine') ne 'Zebra';
151
152 my $z = Koha::Z3950Responder->new( {
153     add_item_status_subfield => $add_item_status_subfield,
154     add_status_multi_subfield => $add_status_multi_subfield,
155     debug => $debug,
156     num_to_prefetch => $prefetch,
157     yaz_options => [ @yaz_options, @ARGV ],
158 } );
159
160 $z->start();