RedirectMatch 301 ^/opac/extras/slimpac/advanced.html$ /opac/en-US/extras/slimpac/advanced.html
# ----------------------------------------------------------------------------------
-# Configure the gateway
+# Configure the gateway and translator
# ----------------------------------------------------------------------------------
OSRFGatewayConfig @sysconfdir@/opensrf_core.xml
+OSRFTranslatorConfig @sysconfdir@/opensrf_core.xml
# Translator memcache server. Default is localhost
# OSRFTranslatorCacheServer 127.0.0.1:11211
RedirectMatch 301 ^/opac/extras/slimpac/advanced.html$ /opac/en-US/extras/slimpac/advanced.html
# ----------------------------------------------------------------------------------
-# Configure the gateway
+# Configure the gateway and translator
# ----------------------------------------------------------------------------------
OSRFGatewayConfig @sysconfdir@/opensrf_core.xml
+OSRFTranslatorConfig @sysconfdir@/opensrf_core.xml
# Translator memcache server. Default is localhost
# OSRFTranslatorCacheServer 127.0.0.1:11211
# Collect files to be used by multiple targets
-autojsbinscripts = @srcdir@/extras/autogen.sh \
- @srcdir@/support-scripts/offline-blocked-list.pl
+autojsbinscripts = @srcdir@/extras/autogen.sh
# Decide which entities to build
$(supportscr)/juv_to_adult.srfsh \
$(supportscr)/thaw_expired_frozen_holds.srfsh \
$(supportscr)/long-overdue-status-update.pl \
- $(supportscr)/action_trigger_runner.pl \
$(supportscr)/purge_holds.srfsh \
$(supportscr)/purge_circulations.srfsh \
$(srcdir)/extras/eg_config \
@srcdir@/extras/import/marc2bre.pl \
@srcdir@/extras/import/marc2sre.pl \
@srcdir@/extras/import/parallel_pg_loader.pl \
+ $(supportscr)/action_trigger_runner.pl \
$(supportscr)/authority_control_fields.pl \
$(supportscr)/authority_authority_linker.pl \
$(supportscr)/eg_db_config \
- $(supportscr)/marc_export
+ $(supportscr)/marc_export \
+ $(supportscr)/offline-blocked-list.pl
gen_docs = \
$(examples)/apache/eg.conf \
$(do_subst) @srcdir@/extras/import/parallel_pg_loader.pl.in > "$@"
chmod 755 "$@"
+$(supportscr)/action_trigger_runner.pl: Makefile $(supportscr)/action_trigger_runner.pl.in
+ $(do_subst) $(supportscr)/action_trigger_runner.pl.in > "$@"
+ chmod 755 "$@"
+
$(supportscr)/authority_authority_linker.pl: Makefile $(supportscr)/authority_authority_linker.pl.in
$(do_subst) $(supportscr)/authority_authority_linker.pl.in > "$@"
chmod 755 "$@"
$(do_subst) $(supportscr)/marc_export.in > "$@"
chmod 755 "$@"
+$(supportscr)/offline-blocked-list.pl: Makefile $(supportscr)/offline-blocked-list.pl.in
+ $(do_subst) $(supportscr)/offline-blocked-list.pl.in > "$@"
+ chmod 755 "$@"
+
$(examples)/apache/eg.conf: Makefile $(examples)/apache/eg.conf.in
$(do_subst) $(examples)/apache/eg.conf.in > "$@"
sed -i 's|BINDIR|@bindir@|g' '$(DESTDIR)@bindir@/long-overdue-status-update.pl'
sed -i 's|SYSCONFDIR|@sysconfdir@|g' '$(DESTDIR)@bindir@/long-overdue-status-update.pl'
sed -i 's|BINDIR|@bindir@|g' '$(DESTDIR)@bindir@/thaw_expired_frozen_holds.srfsh'
- sed -i 's|BINDIR|@bindir@|g' '$(DESTDIR)@bindir@/offline-blocked-list.pl'
sed -i 's|LOCALSTATEDIR|@localstatedir@|g' '$(DESTDIR)@bindir@/oils_ctl.sh'
sed -i 's|SYSCONFDIR|@sysconfdir@|g' '$(DESTDIR)@bindir@/oils_ctl.sh'
+++ /dev/null
-#!/usr/bin/perl
-# ---------------------------------------------------------------
-# Copyright (C) 2009 Equinox Software, Inc
-# Author: Bill Erickson <erickson@esilibrary.com>
-#
-# This program 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 Foundation; either version 2
-# of the License, or (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-# ---------------------------------------------------------------
-use strict;
-use warnings;
-use Getopt::Long;
-use OpenSRF::System;
-use OpenSRF::AppSession;
-use OpenSRF::Utils::JSON;
-use OpenSRF::Utils::Logger qw/$logger/;
-use OpenSRF::EX qw(:try);
-use OpenILS::Utils::Fieldmapper;
-my $req_timeout = 10800;
-
-# DEFAULT values
-
-my $opt_lockfile = '/tmp/action-trigger-LOCK';
-my $opt_osrf_config = '/openils/conf/opensrf_core.xml';
-my $opt_custom_filter = '/openils/conf/action_trigger_filters.json';
-my $opt_max_sleep = 3600; # default to 1 hour
-my $opt_run_pending = 0;
-my $opt_debug_stdout = 0;
-my $opt_help = 0;
-my $opt_verbose;
-my $opt_hooks;
-my $opt_process_hooks = 0;
-my $opt_granularity = undef;
-my $opt_gran_only = undef;
-
-(-f $opt_custom_filter) or undef($opt_custom_filter); # discard default if no file exists
-
-GetOptions(
- 'max-sleep' => \$opt_max_sleep,
- 'osrf-config=s' => \$opt_osrf_config,
- 'run-pending' => \$opt_run_pending,
- 'hooks=s' => \$opt_hooks,
- 'granularity=s' => \$opt_granularity,
- 'granularity-only' => \$opt_gran_only,
- 'process-hooks' => \$opt_process_hooks,
- 'debug-stdout' => \$opt_debug_stdout,
- 'custom-filters=s' => \$opt_custom_filter,
- 'lock-file=s' => \$opt_lockfile,
- 'verbose' => \$opt_verbose,
- 'help' => \$opt_help,
-);
-
-my $max_sleep = $opt_max_sleep;
-
-#XXX need to figure out why this is required...
-$opt_gran_only = $opt_granularity ? 1 : 0;
-
-$opt_lockfile .= '.' . $opt_granularity if ($opt_granularity && $opt_gran_only);
-
-# typical passive hook filters
-my $hook_handlers = {
-
- # default overdue circulations
- 'checkout.due' => {
- context_org => 'circ_lib',
- filter => {
- checkin_time => undef,
- '-or' => [
- {stop_fines => ['MAXFINES']},
- {stop_fines => undef}
- ]
- }
- }
-};
-
-if ($opt_custom_filter) {
- open FILTERS, $opt_custom_filter or die "Cannot read custom filters at $opt_custom_filter";
- $hook_handlers = OpenSRF::Utils::JSON->JSON2perl(join('',(<FILTERS>)));
- close FILTERS;
-}
-
-sub help {
- print <<HELP;
-
-$0 : Create and process action/trigger events
-
- --osrf-config=<config_file>
- OpenSRF core config file. Defaults to:
- /openils/conf/opensrf_core.xml
-
- --custom-filters=<filter_file>
- File containing a JSON Object which describes any hooks that should
- use a user-defined filter to find their target objects. Defaults to:
- /openils/conf/action_trigger_filters.json
-
- --run-pending
- Run pending events
-
- --process-hooks
- Create hook events
-
- --max-sleep=<seconds>
- When in process-hooks mode, wait up to <seconds> for the lock file to
- go away. Defaults to 3600 (1 hour).
-
- --hooks=hook1[,hook2,hook3,...]
- Define which hooks to create events for. If none are defined,
- it defaults to the list of hooks defined in the --custom-filters option.
-
- --granularity=<label>
- Run events with {label} granularity setting, or no granularity setting
-
- --granularity-only
- Used in combination with --granularity, prevents the running of events with no granularity setting
-
- --debug-stdout
- Print server responses to stdout (as JSON) for debugging
-
- --lock-file=<file_name>
- Lock file
-
- --help
- Show this help
-
- Examples:
-
- # To run all pending events. This is what you tell CRON to run at
- # regular intervals
- perl $0 --osrf-config /openils/conf/opensrf_core.xml --run-pending
-
- # To batch create all "checkout.due" events
- perl $0 --osrf-config /openils/conf/opensrf_core.xml --hooks checkout.due
-
-HELP
-}
-
-
-# create events for the specified hooks using the configured filters and context orgs
-sub process_hooks {
- $opt_verbose and print "process_hooks: " . ($opt_process_hooks ? '(start)' : 'SKIPPING') . "\n";
- return unless $opt_process_hooks;
-
- my @hooks = ($opt_hooks) ? split(',', $opt_hooks) : keys(%$hook_handlers);
- my $ses = OpenSRF::AppSession->create('open-ils.trigger');
-
- for my $hook (@hooks) {
- my $config = $$hook_handlers{$hook};
- $opt_verbose and print "process_hooks: $hook " . ($config ? ($opt_granularity || '') : ' NO HANDLER') . "\n";
- $config or next;
-
- my $method = 'open-ils.trigger.passive.event.autocreate.batch';
- $method =~ s/passive/active/ if $config->{active};
-
- my $req = $ses->request($method, $hook, $config->{context_org}, $config->{filter}, $opt_granularity);
-
- my $debug_hook = "'$hook' and filter ".OpenSRF::Utils::JSON->perl2JSON($config->{filter});
- $logger->info("at_runner: creating events for $debug_hook");
-
- my @event_ids;
- while (my $resp = $req->recv(timeout => $req_timeout)) {
- push(@event_ids, $resp->content);
- }
-
- if(@event_ids) {
- $logger->info("at_runner: created ".scalar(@event_ids)." events for $debug_hook");
- } elsif($req->complete) {
- $logger->info("at_runner: no events to create for $debug_hook");
- } else {
- $logger->warn("at_runner: timeout occurred during event creation for $debug_hook");
- }
- }
-}
-
-sub run_pending {
- $opt_verbose and print "run_pending: " .
- ($opt_run_pending ?
- ($opt_granularity ?
- ( $opt_granularity . (
- $opt_gran_only ?
- ' ONLY' :
- ' and NON-GRANULAR'
- )
- ) :
- 'NON-GRANULAR'
- ) :
- 'SKIPPING'
- ) . "\n";
-
- return unless $opt_run_pending;
- my $ses = OpenSRF::AppSession->create('open-ils.trigger');
- my $req = $ses->request('open-ils.trigger.event.run_all_pending' => $opt_granularity => $opt_gran_only);
-
- my $check_lockfile = 1;
- while (my $resp = $req->recv(timeout => $req_timeout)) {
- if ($check_lockfile && -e $opt_lockfile) {
- open LF, $opt_lockfile;
- my $contents = <LF>;
- close LF;
- unlink $opt_lockfile if ($contents == $$);
- $check_lockfile = 0;
- }
- $opt_debug_stdout and print OpenSRF::Utils::JSON->perl2JSON($resp->content) . "\n";
- }
-}
-
-help() and exit if $opt_help;
-help() and exit unless ($opt_run_pending or $opt_process_hooks);
-
-# check the lockfile
-if (-e $opt_lockfile) {
- die "I'm already running with lockfile $opt_lockfile\n" unless ($opt_process_hooks or $opt_granularity);
- # sleeping loop if we're in --process-hooks mode
- while ($max_sleep >= 0 && sleep(1)) {
- last unless ( -e $opt_lockfile );
- $max_sleep--;
- }
-}
-
-# there's a tiny race condition here ... oh well
-die "Someone else has been holding the lockfile $opt_lockfile for at least $opt_max_sleep. Giving up now ...\n" if (-e $opt_lockfile);
-
-# set the lockfile
-open(F, ">$opt_lockfile") or die "Unable to open lockfile $opt_lockfile for writing\n";
-print F $$;
-close F;
-
-try {
- OpenSRF::System->bootstrap_client(config_file => $opt_osrf_config);
- Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL"));
- process_hooks();
- run_pending();
-} otherwise {
- my $e = shift;
- warn "$e\n";
-};
-
-if (-e $opt_lockfile) {
- open LF, $opt_lockfile;
- my $contents = <LF>;
- close LF;
- unlink $opt_lockfile if ($contents == $$);
-}
--- /dev/null
+#!/usr/bin/perl
+# ---------------------------------------------------------------
+# Copyright (C) 2009 Equinox Software, Inc
+# Author: Bill Erickson <erickson@esilibrary.com>
+#
+# This program 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 Foundation; either version 2
+# of the License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+# ---------------------------------------------------------------
+use strict;
+use warnings;
+use Getopt::Long;
+use OpenSRF::System;
+use OpenSRF::AppSession;
+use OpenSRF::Utils::JSON;
+use OpenSRF::Utils::Logger qw/$logger/;
+use OpenSRF::EX qw(:try);
+use OpenILS::Utils::Fieldmapper;
+my $req_timeout = 10800;
+
+# DEFAULT values
+
+my $opt_lockfile = '/tmp/action-trigger-LOCK';
+my $opt_osrf_config = '@sysconfdir@/opensrf_core.xml';
+my $opt_custom_filter = '@sysconfdir@/action_trigger_filters.json';
+my $opt_max_sleep = 3600; # default to 1 hour
+my $opt_run_pending = 0;
+my $opt_debug_stdout = 0;
+my $opt_help = 0;
+my $opt_verbose;
+my $opt_hooks;
+my $opt_process_hooks = 0;
+my $opt_granularity = undef;
+my $opt_gran_only = undef;
+
+(-f $opt_custom_filter) or undef($opt_custom_filter); # discard default if no file exists
+
+GetOptions(
+ 'max-sleep' => \$opt_max_sleep,
+ 'osrf-config=s' => \$opt_osrf_config,
+ 'run-pending' => \$opt_run_pending,
+ 'hooks=s' => \$opt_hooks,
+ 'granularity=s' => \$opt_granularity,
+ 'granularity-only' => \$opt_gran_only,
+ 'process-hooks' => \$opt_process_hooks,
+ 'debug-stdout' => \$opt_debug_stdout,
+ 'custom-filters=s' => \$opt_custom_filter,
+ 'lock-file=s' => \$opt_lockfile,
+ 'verbose' => \$opt_verbose,
+ 'help' => \$opt_help,
+);
+
+my $max_sleep = $opt_max_sleep;
+
+#XXX need to figure out why this is required...
+$opt_gran_only = $opt_granularity ? 1 : 0;
+
+$opt_lockfile .= '.' . $opt_granularity if ($opt_granularity && $opt_gran_only);
+
+# typical passive hook filters
+my $hook_handlers = {
+
+ # default overdue circulations
+ 'checkout.due' => {
+ context_org => 'circ_lib',
+ filter => {
+ checkin_time => undef,
+ '-or' => [
+ {stop_fines => ['MAXFINES']},
+ {stop_fines => undef}
+ ]
+ }
+ }
+};
+
+if ($opt_custom_filter) {
+ open FILTERS, $opt_custom_filter or die "Cannot read custom filters at $opt_custom_filter";
+ $hook_handlers = OpenSRF::Utils::JSON->JSON2perl(join('',(<FILTERS>)));
+ close FILTERS;
+}
+
+sub help {
+ print <<HELP;
+
+$0 : Create and process action/trigger events
+
+ --osrf-config=<config_file>
+ OpenSRF core config file. Defaults to:
+ @sysconfdir@/opensrf_core.xml
+
+ --custom-filters=<filter_file>
+ File containing a JSON Object which describes any hooks that should
+ use a user-defined filter to find their target objects. Defaults to:
+ @sysconfdir@/action_trigger_filters.json
+
+ --run-pending
+ Run pending events
+
+ --process-hooks
+ Create hook events
+
+ --max-sleep=<seconds>
+ When in process-hooks mode, wait up to <seconds> for the lock file to
+ go away. Defaults to 3600 (1 hour).
+
+ --hooks=hook1[,hook2,hook3,...]
+ Define which hooks to create events for. If none are defined,
+ it defaults to the list of hooks defined in the --custom-filters option.
+
+ --granularity=<label>
+ Run events with {label} granularity setting, or no granularity setting
+
+ --granularity-only
+ Used in combination with --granularity, prevents the running of events with no granularity setting
+
+ --debug-stdout
+ Print server responses to stdout (as JSON) for debugging
+
+ --lock-file=<file_name>
+ Lock file
+
+ --help
+ Show this help
+
+ Examples:
+
+ # To run all pending events. This is what you tell CRON to run at
+ # regular intervals
+ perl $0 --osrf-config @sysconfdir@/opensrf_core.xml --run-pending
+
+ # To batch create all "checkout.due" events
+ perl $0 --osrf-config @sysconfdir@/opensrf_core.xml --hooks checkout.due
+
+HELP
+}
+
+
+# create events for the specified hooks using the configured filters and context orgs
+sub process_hooks {
+ $opt_verbose and print "process_hooks: " . ($opt_process_hooks ? '(start)' : 'SKIPPING') . "\n";
+ return unless $opt_process_hooks;
+
+ my @hooks = ($opt_hooks) ? split(',', $opt_hooks) : keys(%$hook_handlers);
+ my $ses = OpenSRF::AppSession->create('open-ils.trigger');
+
+ for my $hook (@hooks) {
+ my $config = $$hook_handlers{$hook};
+ $opt_verbose and print "process_hooks: $hook " . ($config ? ($opt_granularity || '') : ' NO HANDLER') . "\n";
+ $config or next;
+
+ my $method = 'open-ils.trigger.passive.event.autocreate.batch';
+ $method =~ s/passive/active/ if $config->{active};
+
+ my $req = $ses->request($method, $hook, $config->{context_org}, $config->{filter}, $opt_granularity);
+
+ my $debug_hook = "'$hook' and filter ".OpenSRF::Utils::JSON->perl2JSON($config->{filter});
+ $logger->info("at_runner: creating events for $debug_hook");
+
+ my @event_ids;
+ while (my $resp = $req->recv(timeout => $req_timeout)) {
+ push(@event_ids, $resp->content);
+ }
+
+ if(@event_ids) {
+ $logger->info("at_runner: created ".scalar(@event_ids)." events for $debug_hook");
+ } elsif($req->complete) {
+ $logger->info("at_runner: no events to create for $debug_hook");
+ } else {
+ $logger->warn("at_runner: timeout occurred during event creation for $debug_hook");
+ }
+ }
+}
+
+sub run_pending {
+ $opt_verbose and print "run_pending: " .
+ ($opt_run_pending ?
+ ($opt_granularity ?
+ ( $opt_granularity . (
+ $opt_gran_only ?
+ ' ONLY' :
+ ' and NON-GRANULAR'
+ )
+ ) :
+ 'NON-GRANULAR'
+ ) :
+ 'SKIPPING'
+ ) . "\n";
+
+ return unless $opt_run_pending;
+ my $ses = OpenSRF::AppSession->create('open-ils.trigger');
+ my $req = $ses->request('open-ils.trigger.event.run_all_pending' => $opt_granularity => $opt_gran_only);
+
+ my $check_lockfile = 1;
+ while (my $resp = $req->recv(timeout => $req_timeout)) {
+ if ($check_lockfile && -e $opt_lockfile) {
+ open LF, $opt_lockfile;
+ my $contents = <LF>;
+ close LF;
+ unlink $opt_lockfile if ($contents == $$);
+ $check_lockfile = 0;
+ }
+ $opt_debug_stdout and print OpenSRF::Utils::JSON->perl2JSON($resp->content) . "\n";
+ }
+}
+
+help() and exit if $opt_help;
+help() and exit unless ($opt_run_pending or $opt_process_hooks);
+
+# check the lockfile
+if (-e $opt_lockfile) {
+ die "I'm already running with lockfile $opt_lockfile\n" unless ($opt_process_hooks or $opt_granularity);
+ # sleeping loop if we're in --process-hooks mode
+ while ($max_sleep >= 0 && sleep(1)) {
+ last unless ( -e $opt_lockfile );
+ $max_sleep--;
+ }
+}
+
+# there's a tiny race condition here ... oh well
+die "Someone else has been holding the lockfile $opt_lockfile for at least $opt_max_sleep. Giving up now ...\n" if (-e $opt_lockfile);
+
+# set the lockfile
+open(F, ">$opt_lockfile") or die "Unable to open lockfile $opt_lockfile for writing\n";
+print F $$;
+close F;
+
+try {
+ OpenSRF::System->bootstrap_client(config_file => $opt_osrf_config);
+ Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL"));
+ process_hooks();
+ run_pending();
+} otherwise {
+ my $e = shift;
+ warn "$e\n";
+};
+
+if (-e $opt_lockfile) {
+ open LF, $opt_lockfile;
+ my $contents = <LF>;
+ close LF;
+ unlink $opt_lockfile if ($contents == $$);
+}
+++ /dev/null
-#!/usr/bin/perl
-#
-
-use strict; use warnings;
-
-use Getopt::Long;
-
-use OpenSRF::Utils::JSON; # for the oils_requestor approach
-use IPC::Open2 qw/open2/; # for the oils_requestor approach
-use Net::Domain qw/hostfqdn/; # for the oils_requestor approach
-
-# use OpenSRF::EX qw(:try); # for traditional approach
-use OpenSRF::System; # for traditional approach
-use OpenSRF::AppSession; # for traditional approach
-
-### USAGE
-
-sub usage {
- my $defhost = hostfqdn();
- return <<END_OF_USAGE
-
-$0
-
-Generate a file of blocked barcodes for offline use. There are two styles of
-invocation, old and new (using oils_requestor). See WARNING.
-
-By default, all known blocked barcodes are output. Override with --barcodes option.
-
-OPTIONS:
-
---oldstyle Use traditional OpenSRF calls default: OFF.
---verbose give feedback on STDERR, including number of barcodes fetched
---help print this message
-
---config =[file] core config file default: /openils/conf/opensrf_core.xml
---requestor=[/path/to/requstor] default: /openils/bin/oils_requestor
---hostname =[my.fqdn.com] default: hostfqdn()
- (Only used by new style.)
- May be necessary if hostfqdn does not match router configs.
- Currently your hostfqdn is '$defhost'.
-
---barcodes [key=eg_code] default: ALL
- Specify what kind of barcodes to fetch and how to tag them in the output.
- The key is the (one letter) tag used in the offline file,
- and the eg_code is the component of the SRF call that targets the barcodes
- (like "lost"). NOTE: This option can be specified multiple times.
-
-
-EXAMPLES:
-
-# Use the old style with a custom config
-$0 --config /openils/conf/test_core.xml --oldstyle
-
-# Append just lost and barred barcodes to file, showing feedback on STDERR
-$0 --verbose --barcodes L=lost --barcodes B=barred >>file
-
-WARNING:
-The new style offers performance benefits but seems to lose one line of data per call.
-
-END_OF_USAGE
-}
-
-### DEFAULTS
-
-my $config = '/openils/conf/opensrf_core.xml';
-my $oils_reqr = '/openils/bin/oils_requestor';
-my $context = 'opensrf';
-my $hostname = hostfqdn();
-my $help = 0;
-my $verbose = 0;
-my $approach = 0;
-my %types = ();
-
-GetOptions(
- "barcodes=s" => \%types,
- "config:s" => \$config,
- "oldstyle" => \$approach,
- "hostname:s" => \$hostname,
- "requestor:s" => \$oils_reqr,
- "verbose" => \$verbose,
- "help" => \$help,
-);
-
-### SANITY CHECK
-
-print usage() and exit if $help;
-
-(-r $config) or die "Cannot read config file\n";
-
-%types or %types = ( # If you don't specify, you get'm all.
- L => 'lost',
- E => 'expired', # Possibly too many, making the file too large for download
- B => 'barred',
- D => 'penalized',
-);
-
-my %counts = ();
-foreach (keys %types) {
- $counts{$_} = 0; # initialize count
-}
-
-### FEEDBACK
-
-if ($verbose) {
- print STDERR "verbose feedback is ON\n";
- print STDERR "hostname: $hostname\n";
- print STDERR "barcodes types:\n";
- foreach (sort keys %types) {
- print STDERR " $_ ==> $types{$_}\n";
- }
- print STDERR "Using the ", ($approach ? 'traditional' : 'new oils'), " approach\n";
-}
-
-### Engine of the new style piped approach
-### Note, this appears to LOSE DATA, specifically one barcode value from each call.
-
-sub runmethod {
- my $method = shift;
- my $key = shift;
- my $command = "echo \"open-ils.storage $method\" | $oils_reqr -f $config -c $context -h $hostname";
- $verbose and print STDERR "\nCOMMAND:\n-> $command\n";
-
- my ($child_stdout, $child_stdin);
- my $pid = open2($child_stdout, $child_stdin, $command);
- for my $barcode (<$child_stdout>) {
- next if $barcode =~ /^oils/o; # hack to chop out the oils_requestor prompt
- next if $barcode =~ /^Connected to OpenSRF/o;
- chomp $barcode;
- $barcode = OpenSRF::Utils::JSON->JSON2perl($barcode);
- print "$barcode $key\n" if $barcode;
- $counts{$key}++;
- }
- close($child_stdout);
- close($child_stdin);
- waitpid($pid, 0); # don't leave any zombies (see ipc::open2)
-}
-
-### MAIN
-
-if (! $approach) {
- # ------------------------------------------------------------
- # This sends the method calls to storage via oils_requestor,
- # which is able to process the results much faster
- # Make this the default for now.
- # ------------------------------------------------------------
-
- foreach my $key (keys %types) {
- runmethod('open-ils.storage.actor.user.' . $types{$key} . '_barcodes', $key);
- }
-
-} else {
- # ------------------------------------------------------------
- # Uses the traditional opensrf Perl API approach
- # ------------------------------------------------------------
-
- OpenSRF::System->bootstrap_client( config_file => $config );
-
- my $ses = OpenSRF::AppSession->connect( 'open-ils.storage' );
-
- foreach my $key (keys %types) {
- my $req = $ses->request( 'open-ils.storage.actor.user.' . $types{$key} . '_barcodes' );
- while (my $resp = $req->recv) {
- print $resp->content, " $key\n";
- $counts{$key}++;
- }
- $req->finish;
- }
-
- $ses->disconnect;
- $ses->finish;
-}
-
-if ($verbose) {
- print STDERR "\nBarcodes retrieved:\n";
- foreach (sort keys %types) {
- printf STDERR " %s ==> %9s ==> %d\n", $_, $types{$_}, $counts{$_};
- }
- print STDERR "\ndone\n";
-}
-
--- /dev/null
+#!/usr/bin/perl
+#
+
+use strict; use warnings;
+
+use Getopt::Long;
+
+use OpenSRF::Utils::JSON; # for the oils_requestor approach
+use IPC::Open2 qw/open2/; # for the oils_requestor approach
+use Net::Domain qw/hostfqdn/; # for the oils_requestor approach
+
+# use OpenSRF::EX qw(:try); # for traditional approach
+use OpenSRF::System; # for traditional approach
+use OpenSRF::AppSession; # for traditional approach
+
+### USAGE
+
+sub usage {
+ my $defhost = hostfqdn();
+ return <<END_OF_USAGE
+
+$0
+
+Generate a file of blocked barcodes for offline use. There are two styles of
+invocation, old and new (using oils_requestor). See WARNING.
+
+By default, all known blocked barcodes are output. Override with --barcodes option.
+
+OPTIONS:
+
+--oldstyle Use traditional OpenSRF calls default: OFF.
+--verbose give feedback on STDERR, including number of barcodes fetched
+--help print this message
+
+--config =[file] core config file default: @sysconfdir@/opensrf_core.xml
+--requestor=[/path/to/requstor] default: @sysconfdir@/bin/oils_requestor
+--hostname =[my.fqdn.com] default: hostfqdn()
+ (Only used by new style.)
+ May be necessary if hostfqdn does not match router configs.
+ Currently your hostfqdn is '$defhost'.
+
+--barcodes [key=eg_code] default: ALL
+ Specify what kind of barcodes to fetch and how to tag them in the output.
+ The key is the (one letter) tag used in the offline file,
+ and the eg_code is the component of the SRF call that targets the barcodes
+ (like "lost"). NOTE: This option can be specified multiple times.
+
+
+EXAMPLES:
+
+# Use the old style with a custom config
+$0 --config @sysconfdir@/conf/test_core.xml --oldstyle
+
+# Append just lost and barred barcodes to file, showing feedback on STDERR
+$0 --verbose --barcodes L=lost --barcodes B=barred >>file
+
+WARNING:
+The new style offers performance benefits but seems to lose one line of data per call.
+
+END_OF_USAGE
+}
+
+### DEFAULTS
+
+my $config = '@sysconfdir@/opensrf_core.xml';
+my $oils_reqr = '@bindir@/oils_requestor';
+my $context = 'opensrf';
+my $hostname = hostfqdn();
+my $help = 0;
+my $verbose = 0;
+my $approach = 0;
+my %types = ();
+
+GetOptions(
+ "barcodes=s" => \%types,
+ "config:s" => \$config,
+ "oldstyle" => \$approach,
+ "hostname:s" => \$hostname,
+ "requestor:s" => \$oils_reqr,
+ "verbose" => \$verbose,
+ "help" => \$help,
+);
+
+### SANITY CHECK
+
+print usage() and exit if $help;
+
+(-r $config) or die "Cannot read config file\n";
+
+%types or %types = ( # If you don't specify, you get'm all.
+ L => 'lost',
+ E => 'expired', # Possibly too many, making the file too large for download
+ B => 'barred',
+ D => 'penalized',
+);
+
+my %counts = ();
+foreach (keys %types) {
+ $counts{$_} = 0; # initialize count
+}
+
+### FEEDBACK
+
+if ($verbose) {
+ print STDERR "verbose feedback is ON\n";
+ print STDERR "hostname: $hostname\n";
+ print STDERR "barcodes types:\n";
+ foreach (sort keys %types) {
+ print STDERR " $_ ==> $types{$_}\n";
+ }
+ print STDERR "Using the ", ($approach ? 'traditional' : 'new oils'), " approach\n";
+}
+
+### Engine of the new style piped approach
+### Note, this appears to LOSE DATA, specifically one barcode value from each call.
+
+sub runmethod {
+ my $method = shift;
+ my $key = shift;
+ my $command = "echo \"open-ils.storage $method\" | $oils_reqr -f $config -c $context -h $hostname";
+ $verbose and print STDERR "\nCOMMAND:\n-> $command\n";
+
+ my ($child_stdout, $child_stdin);
+ my $pid = open2($child_stdout, $child_stdin, $command);
+ for my $barcode (<$child_stdout>) {
+ next if $barcode =~ /^oils/o; # hack to chop out the oils_requestor prompt
+ next if $barcode =~ /^Connected to OpenSRF/o;
+ chomp $barcode;
+ $barcode = OpenSRF::Utils::JSON->JSON2perl($barcode);
+ print "$barcode $key\n" if $barcode;
+ $counts{$key}++;
+ }
+ close($child_stdout);
+ close($child_stdin);
+ waitpid($pid, 0); # don't leave any zombies (see ipc::open2)
+}
+
+### MAIN
+
+if (! $approach) {
+ # ------------------------------------------------------------
+ # This sends the method calls to storage via oils_requestor,
+ # which is able to process the results much faster
+ # Make this the default for now.
+ # ------------------------------------------------------------
+
+ foreach my $key (keys %types) {
+ runmethod('open-ils.storage.actor.user.' . $types{$key} . '_barcodes', $key);
+ }
+
+} else {
+ # ------------------------------------------------------------
+ # Uses the traditional opensrf Perl API approach
+ # ------------------------------------------------------------
+
+ OpenSRF::System->bootstrap_client( config_file => $config );
+
+ my $ses = OpenSRF::AppSession->connect( 'open-ils.storage' );
+
+ foreach my $key (keys %types) {
+ my $req = $ses->request( 'open-ils.storage.actor.user.' . $types{$key} . '_barcodes' );
+ while (my $resp = $req->recv) {
+ print $resp->content, " $key\n";
+ $counts{$key}++;
+ }
+ $req->finish;
+ }
+
+ $ses->disconnect;
+ $ses->finish;
+}
+
+if ($verbose) {
+ print STDERR "\nBarcodes retrieved:\n";
+ foreach (sort keys %types) {
+ printf STDERR " %s ==> %9s ==> %d\n", $_, $types{$_}, $counts{$_};
+ }
+ print STDERR "\ndone\n";
+}
+