--- /dev/null
+#!/usr/bin/perl
+use strict;
+use warnings;
+use DateTime;
+use OpenSRF::AppSession;
+use OpenILS::Utils::CStoreEditor;
+use OpenILS::Utils::Cronscript;
+use OpenILS::Utils::Fieldmapper;
+use OpenSRF::Utils::Logger qw/$logger/;
+binmode(STDOUT, ":utf8");
+
+my %defaults = (
+ 'osrf-config=s' => '/openils/conf/opensrf_core.xml',
+ 'response-file=s' => '',
+ 'verbose' => 0
+);
+
+sub help {
+ print <<HELP;
+
+Collect CSV notification output and deliver to 3rd party
+
+# fetch notification status/response file
+$0
+
+HELP
+ exit;
+}
+
+my $o = OpenILS::Utils::Cronscript->new(\%defaults);
+my $opts = $o->MyGetOptions();
+$o->bootstrap;
+
+my $file = $opts->{'response-file'};
+open(FILE, $file) or
+ die "Unable to open response file: '$file' : $!\n";
+
+my $e = $o->editor(connect => 1);
+
+while (<FILE>) {
+ chomp;
+
+ my ($id, $stat) = /"(.+)","(.+)"/g;
+ next unless $id and $stat;
+
+ $logger->info("csv: processing event $id; stat $stat");
+
+ my $event = $e->retrieve_action_trigger_event($id);
+
+ if (!$event) {
+ $logger->warn("csv: unable to find event $id");
+ next;
+ }
+
+ if ($event->async_output) {
+ $logger->info("csv: skipping event $id; async_output already set");
+ next;
+ }
+
+ $e->xact_begin;
+
+ # store the response output
+ my $output = Fieldmapper::action_trigger::event_output->new;
+ $output->data($stat);
+
+ unless ($e->create_action_trigger_event_output($output)) {
+ $logger->warn("csv: error creating event ".
+ "output for event $id: ". $e->die_event);
+ next;
+ }
+
+ # link the async response output to the original event
+ $event->async_output($output->id);
+
+ unless ($e->update_action_trigger_event($event)) {
+ $logger->warn("csv: error updating event $id: ". $e->die_event);
+ next;
+ }
+
+ $e->xact_commit;
+}
+
+$e->disconnect;
+
+
my @event_defs = split(/,/, $opts->{'event-defs'});
+die "--event-defs required\n" unless @event_defs;
+
if ($verbose) {
print "processing event_defs = @event_defs\n";
print "start_date = $start_date\n";
# dump the CSV chunk from each event output
while (my $resp = $req->recv(timeout => 12000)) {
+ if ($req->failed) {
+ warn $req->failed;
+ last;
+ };
my $content = $resp->content or next;
print $content->{data};
}