Bugzilla – Attachment 103705 Details for
Bug 25252
Add script to export bib data to CollectionHQ
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 25252: Add script to export bib data to CollectionHQ
Bug-25252-Add-script-to-export-bib-data-to-Collect.patch (text/plain), 4.32 KB, created by
Bernardo Gonzalez Kriegel
on 2020-04-24 19:53:29 UTC
(
hide
)
Description:
Bug 25252: Add script to export bib data to CollectionHQ
Filename:
MIME Type:
Creator:
Bernardo Gonzalez Kriegel
Created:
2020-04-24 19:53:29 UTC
Size:
4.32 KB
patch
obsolete
>From c0223fd09edad6a434614fb42c4e627f29f1b90c Mon Sep 17 00:00:00 2001 >From: David Roberts <david@koha-ptfs.co.uk> >Date: Wed, 22 Apr 2020 14:03:29 +0000 >Subject: [PATCH] Bug 25252: Add script to export bib data to CollectionHQ > >This script adds the capability to export bibliographic data to CollectionHQ via a cronjob. > >To test: > >1) Apply the patch >2) Run the script and an export file should be created in /tmp >3) If you have a valid username and password for the CollectionHQ ftp >server, add these credentials into lines 83 and 84 and run the script >again to ensure it transfers correctly. > >Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> >--- > misc/export2collectionhq.pl | 131 ++++++++++++++++++++++++++++++++++++ > 1 file changed, 131 insertions(+) > create mode 100755 misc/export2collectionhq.pl > >diff --git a/misc/export2collectionhq.pl b/misc/export2collectionhq.pl >new file mode 100755 >index 0000000000..7d8c5b9527 >--- /dev/null >+++ b/misc/export2collectionhq.pl >@@ -0,0 +1,131 @@ >+#!/usr/bin/env perl >+ >+# >+# Copyright 2012 PTFS Europe Ltd >+# This file is part of Koha. >+# >+# Koha 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 3 of the License, or (at your option) any later >+# version. >+# >+# Koha 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. >+# >+# You should have received a copy of the GNU General Public License along with >+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, >+# Suite 330, Boston, MA 02111-1307 USA >+ >+use strict; >+use warnings; >+use FindBin; >+use lib "$FindBin::Bin/../.."; >+use Carp; >+use C4::Context; >+use C4::Auth; >+use C4::Output; >+use C4::Biblio; # GetMarcBiblio GetXmlBiblio >+use C4::Koha; # GetItemTypes >+use Net::FTP; >+use Getopt::Long; >+use Pod::Usage; >+ >+sub usage { >+ pod2usage( -verbose => 2 ); >+ exit; >+} >+ >+$| = 1; >+ >+# command-line parameters >+ my $want_help = 0; >+ >+my $result = GetOptions( >+ 'h|help' => \$want_help >+); >+ >+binmode( STDOUT, ":encoding(UTF-8)" ); >+ >+if ( not $result or $want_help ) { >+ usage(); >+} >+ >+unless ( chdir '/tmp' ) { >+ croak 'Unable to cd to /tmp'; >+} >+ >+my $filename = get_filename(); >+ >+write_file($filename); >+ >+transfer_file($filename); >+ >+sub write_file { >+ my $export_filename = shift; >+ my $dbh = C4::Context->dbh; >+ >+ my $query = >+ 'SELECT biblioitems.biblionumber FROM biblioitems WHERE biblionumber >0 '; >+ >+ my $sth = $dbh->prepare($query); >+ $sth->execute(); >+ >+ open my $fh, '>:encoding(utf8)', $export_filename >+ or croak "Cannot open $export_filename : $!"; >+ >+ while ( my ($biblionumber) = $sth->fetchrow_array ) { >+ #my $marc_record = GetMarcBiblio($biblionumber,1); >+ my $marc_record = GetMarcBiblio( { biblionumber => $biblionumber,embed_items =>1 } ); >+ if ($marc_record) { >+ print {$fh} $marc_record->as_usmarc(); >+ } >+ } >+ if ( !close $fh ) { >+ croak "Writing to $export_filename failed on close"; >+ } >+ return; >+} >+ >+sub get_filename { >+ my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ); >+ my @tm = localtime(); >+ my $month = $tm[4]; >+ my $year = $tm[5] - 100; >+ my $name = 'export' . $abbr[$month] . $year; >+ $name .= '.mrc'; >+ >+ # will need to add a directory & unique date id to file >+ return $name; >+} >+ >+sub transfer_file { >+ my $marc_file = shift; >+ my $remote = 'ftp.emea.collectionhq.com'; >+ my $username = q{INSERT USERNAME HERE}; >+ my $password = q{INSERT PASSWORD HERE}; >+ >+ my $ftp = Net::FTP->new( $remote, Debug => 0 ) >+ or croak "Cannot connect to CollectionHQ $@"; >+ >+ $ftp->login( $username, $password ) >+ or croak 'Cannot login to CollectionHQ ', $ftp->message; >+ $ftp->binary(); >+ $ftp->put($marc_file); >+ >+ $ftp->quit; >+ >+ return; >+} >+ >+=head1 NAME >+ >+export2collectionhq.pl >+ >+=head1 SYNOPSIS >+ >+ export2collectionhq.pl >+ >+=head1 DESCRIPTION >+ >+This script exports bibliographic data to CollectionHQ. It is imperative that the username and password are all edited in the script for successful transfer to CollectionHQ. >-- >2.17.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 25252
:
103482
|
103671
|
103691
| 103705