Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/env perl |
|
|
2 |
|
3 |
# |
4 |
# This file is part of Koha. |
5 |
# |
6 |
# Koha is free software; you can redistribute it and/or modify it under the |
7 |
# terms of the GNU General Public License as published by the Free Software |
8 |
# Foundation; either version 2 of the License, or (at your option) any later |
9 |
# version. |
10 |
# |
11 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
12 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
13 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
14 |
# |
15 |
# You should have received a copy of the GNU General Public License along with |
16 |
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, |
17 |
# Suite 330, Boston, MA 02111-1307 USA |
18 |
|
19 |
use strict; |
20 |
use warnings; |
21 |
use FindBin; |
22 |
use lib "$FindBin::Bin/../.."; |
23 |
use Carp; |
24 |
use C4::Context; |
25 |
use C4::Auth; |
26 |
use C4::Output; |
27 |
use C4::Biblio; # GetMarcBiblio GetXmlBiblio |
28 |
use C4::Koha; # GetItemTypes |
29 |
use Net::FTP; |
30 |
|
31 |
unless ( chdir '/tmp' ) { |
32 |
croak 'Unable to cd to /tmp'; |
33 |
} |
34 |
|
35 |
my $filename = get_filename(); |
36 |
|
37 |
write_file($filename); |
38 |
|
39 |
transfer_file($filename); |
40 |
|
41 |
sub write_file { |
42 |
my $export_filename = shift; |
43 |
my $dbh = C4::Context->dbh; |
44 |
|
45 |
my $query = |
46 |
# 'SELECT distinct biblioitems.biblionumber FROM biblioitems WHERE biblionumber >0 '; |
47 |
'SELECT distinct biblioitems.biblionumber FROM biblioitems LEFT JOIN items USING (biblioitemnumber) WHERE biblioitems.biblionumber >0 '; |
48 |
|
49 |
my $sth = $dbh->prepare($query); |
50 |
$sth->execute(); |
51 |
|
52 |
open my $fh, '>:encoding(utf8)', $export_filename |
53 |
or croak "Cannot open $export_filename : $!"; |
54 |
|
55 |
while ( my ($biblionumber) = $sth->fetchrow_array ) { |
56 |
# my $marc_record = GetMarcBiblio($biblionumber, 1); |
57 |
my $marc_record = GetMarcBiblio({ biblionumber => $biblionumber,embed_items => 1}); |
58 |
if ($marc_record) { |
59 |
print {$fh} $marc_record->as_usmarc(); |
60 |
} |
61 |
} |
62 |
if ( !close $fh ) { |
63 |
croak "Writing to $export_filename failed on close"; |
64 |
} |
65 |
return; |
66 |
} |
67 |
|
68 |
sub get_filename { |
69 |
my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ); |
70 |
my @tm = localtime(); |
71 |
my $month = $tm[4]; |
72 |
my $year = $tm[5] - 100; |
73 |
my $name = 'INSERT FILE NAME HERE' . $abbr[$month] . $year; |
74 |
|
75 |
$name .= '.mrc'; |
76 |
|
77 |
# will need to add a directory & unique date id to file |
78 |
return $name; |
79 |
} |
80 |
|
81 |
sub transfer_file { |
82 |
my $marc_file = shift; |
83 |
my $remote = 'ftp.epnet.com'; |
84 |
my $username = q(INSERT USERNAME HERE); |
85 |
my $password = q(INSERT PASSWORD HERE); |
86 |
|
87 |
my $ftp = Net::FTP->new( $remote, Passive => 1, Debug => 0 ) |
88 |
or croak "Cannot connect to epnet: $@"; |
89 |
|
90 |
$ftp->login( $username, $password ) |
91 |
or croak 'Cannot login to Epnet ', $ftp->message; |
92 |
$ftp->cwd("full") |
93 |
or die "Cannot change working directory ", $ftp->message; |
94 |
$ftp->put($marc_file); |
95 |
|
96 |
$ftp->quit; |
97 |
|
98 |
return; |
99 |
} |