Bug 23463: Remove DelItemCheck and ItemSafeToDelete
[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
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21
22 use Carp;
23 use File::Basename;
24 use Getopt::Long qw(:config no_ignore_case);
25 use Pod::Usage;
26
27 use Koha::Config;
28 use Koha::Z3950Responder;
29
30 =head1 SYNOPSIS
31
32    z3950_responder.pl [-h|--help] [--man] [-a <pdufile>] [-v <loglevel>] [-l <logfile>] [-u <user>]
33                       [-c <config>] [-t <minutes>] [-k <kilobytes>] [-d <daemon>] [-p <pidfile>]
34                       [-C certfile] [-zKiDST1] [-m <time-format>] [-w <directory>] [--debug]
35                       [--add-item-status=SUBFIELD] [--prefetch=NUM_RECORDS] [--config-dir=<directory>]
36                       [<listener-addr>... ]
37
38 =head1 OPTIONS
39
40 See https://software.indexdata.com/yaz/doc/server.invocation.html for more information about YAZ options
41 not described below.
42
43 =over 8
44
45 =item B<--help>
46
47 Prints a brief usage message and exits.
48
49 =item B<--man>
50
51 Displays manual page and exits.
52
53 =item B<--debug>
54
55 Turns on debug logging to the screen and the single-process mode.
56
57 =item B<--add-item-status=SUBFIELD>
58
59 If given, adds item status information to the given subfield.
60
61 =item B<--add-status-multi-subfield>
62
63 With the above, instead of putting multiple item statuses in one subfield, adds a subfield for each
64 status string.
65
66 =item B<--prefetch=NUM_RECORDS>
67
68 Number of records to prefetch. Defaults to 20.
69
70 =item B<--config-dir=directory>
71
72 Directory where to find configuration files required for proper operation. Defaults to z3950 under
73 the Koha config directory.
74
75 =back
76
77 =head1 CONFIGURATION
78
79 The item status strings added by B<--add-item-status> can be configured with the B<Z3950_STATUS>
80 authorized value, using the following keys:
81
82 =over 4
83
84 =item AVAILABLE
85
86 =item CHECKED_OUT
87
88 =item LOST
89
90 =item NOT_FOR_LOAN
91
92 =item DAMAGED
93
94 =item WITHDRAWN
95
96 =item IN_TRANSIT
97
98 =item ON_HOLD
99
100 =back
101
102 =cut
103
104 my $add_item_status_subfield;
105 my $add_status_multi_subfield;
106 my $debug = 0;
107 my $help;
108 my $man;
109 my $prefetch = 20;
110 my $config_dir = '';
111
112 my @yaz_options;
113
114 sub add_yaz_option {
115     my ( $opt_name, $opt_value ) = @_;
116
117     push @yaz_options, "-$opt_name", "$opt_value";
118 }
119
120 sub pass_yaz_option {
121     my ( $opt_name ) = @_;
122
123     push @yaz_options, "-$opt_name";
124 }
125
126 GetOptions(
127     '-h|help' => \$help,
128     '--man' => \$man,
129     '--debug' => \$debug,
130     '--add-item-status=s' => \$add_item_status_subfield,
131     '--add-status-multi-subfield' => \$add_status_multi_subfield,
132     '--prefetch=i' => \$prefetch,
133     '--config-dir=s' => \$config_dir,
134     # Pass through YAZ options.
135     'a=s' => \&add_yaz_option,
136     'v=s' => \&add_yaz_option,
137     'l=s' => \&add_yaz_option,
138     'u=s' => \&add_yaz_option,
139     'c=s' => \&add_yaz_option,
140     't=s' => \&add_yaz_option,
141     'k=s' => \&add_yaz_option,
142     'd=s' => \&add_yaz_option,
143     'p=s' => \&add_yaz_option,
144     'C=s' => \&add_yaz_option,
145     'm=s' => \&add_yaz_option,
146     'w=s' => \&add_yaz_option,
147     'z' => \&pass_yaz_option,
148     'K' => \&pass_yaz_option,
149     'i' => \&pass_yaz_option,
150     'D' => \&pass_yaz_option,
151     'S' => \&pass_yaz_option,
152     'T' => \&pass_yaz_option,
153     '1' => \&pass_yaz_option
154 ) || pod2usage(2);
155
156 pod2usage(1) if $help;
157 pod2usage( -verbose => 2 ) if $man;
158
159 # If config_dir is not defined, default to z3950 under the Koha config directory
160 if (!$config_dir) {
161     (undef, $config_dir) = fileparse(Koha::Config->guess_koha_conf);
162     $config_dir .= 'z3950/';
163 } else {
164     $config_dir .= '/' if ($config_dir !~ /\/$/);
165 }
166
167 # Create and start the server.
168
169 my $z = Koha::Z3950Responder->new( {
170     add_item_status_subfield => $add_item_status_subfield,
171     add_status_multi_subfield => $add_status_multi_subfield,
172     debug => $debug,
173     num_to_prefetch => $prefetch,
174     config_dir => $config_dir,
175     yaz_options => [ @yaz_options, @ARGV ],
176 } );
177
178 $z->start();