]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/support-scripts/edi_fetcher.pl
cdeac7c453438737e1989420c51aa09b81309d04
[working/Evergreen.git] / Open-ILS / src / support-scripts / edi_fetcher.pl
1 #!/usr/bin/perl
2 # ---------------------------------------------------------------
3 # Copyright (C) 2010 Equinox Software, Inc
4 # Author: Joe Atzberger <jatzberger@esilibrary.com>
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 # ---------------------------------------------------------------
16
17 use strict;
18 use warnings;
19
20 use Data::Dumper;
21 use vars qw/$debug/;
22
23 use OpenILS::Application::Acq::EDI;
24 use OpenILS::Utils::CStoreEditor;   # needs init() after IDL is loaded (by Cronscript session)
25 use OpenILS::Utils::Cronscript;
26
27 INIT {
28     $debug = 1;
29 }
30
31 OpenILS::Utils::Cronscript->new()->session('open-ils.acq') or die "No session created";
32 OpenILS::Utils::CStoreEditor::init();
33
34 sub editor {
35     my $ed = OpenILS::Utils::CStoreEditor->new(@_) or die "Failed to get new CStoreEditor";
36     return $ed;
37 }
38
39
40 my $e = editor();
41 my $set = $e->retrieve_all_acq_edi_account();
42 my $total_accts = scalar(@$set);
43
44 ($total_accts) or die "No EDI accounts found in database (table: acq.edi_account)";
45
46 print "EDI Accounts Total : ", scalar(@$set), "\n";
47
48 my $subset = $e->search_acq_edi_account([
49     {'+acqpro' => {active => 't'}},
50     {
51         'join' => 'acqpro',
52         flesh => 1,
53         flesh_fields => {acqedi => ['provider']},
54     }
55 ]);
56
57 print "EDI Accounts Active: ", scalar(@$subset), "\n";
58
59 my $res = OpenILS::Application::Acq::EDI->retrieve_core();
60 print "Files retrieved: ", scalar(@$res), "\n";
61 $debug and print "retrieve_core returns ", scalar(@$res),  " ids: " . join(', ', @$res), "\n";
62
63 $debug and print map {Dumper($_) . "\n"} @$subset;
64 print "\ndone\n";
65
66 __END__
67
68 =head1 edi_fetcher.pl - A script for retrieving and processing EDI files from remote accounts.
69
70 Note: This script is expected to be run via crontab.
71
72 Note: Depending on your vendors and you own network environment, you may want to set/export
73 the environmental variable FTP_PASSIVE like:
74
75     export FTP_PASSIVE=1
76     # or
77     FTP_PASSIVE=1 Open-ILS/src/support-scripts/edi_fetcher.pl
78
79