Bugzilla – Attachment 11033 Details for
Bug 8376
Command line utility for exporting borrowers
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 8376: New script to export borrowers misc/export_borrowers.pl
Bug-8376-New-script-to-export-borrowers-miscexport.patch (text/plain), 4.10 KB, created by
Robin Sheat
on 2012-07-20 08:41:50 UTC
(
hide
)
Description:
Bug 8376: New script to export borrowers misc/export_borrowers.pl
Filename:
MIME Type:
Creator:
Robin Sheat
Created:
2012-07-20 08:41:50 UTC
Size:
4.10 KB
patch
obsolete
>From 6db8c77a6f66e248da5b96b79f1c64371e556426 Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Fri, 6 Jul 2012 12:31:48 +0200 >Subject: [PATCH] Bug 8376: New script to export borrowers > misc/export_borrowers.pl > >This script prints to standard output what is returned by >GetMemberDetails in CSV format. >Exported fields can be specified with option -f. If no -f option is >specified, all fields are exported. > >Signed-off-by: Gaetan Boisson <gaetan.boisson@biblibre.com> >Signed-off-by: Robin Sheat <robin@catalyst.net.nz> > >Amended with some code to better handle bad data. >--- > misc/export_borrowers.pl | 114 ++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 114 insertions(+) > create mode 100755 misc/export_borrowers.pl > >diff --git a/misc/export_borrowers.pl b/misc/export_borrowers.pl >new file mode 100755 >index 0000000..4e3f8f3 >--- /dev/null >+++ b/misc/export_borrowers.pl >@@ -0,0 +1,114 @@ >+#!/usr/bin/perl >+ >+# Copyright 2011 BibLibre >+# >+# 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 2 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., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+# Script to export borrowers >+ >+use Modern::Perl; >+use Text::CSV; >+use Getopt::Long qw(:config no_ignore_case); >+ >+use C4::Context; >+use C4::Members; >+ >+use encoding 'utf8'; >+ >+sub print_usage { >+ ( my $basename = $0 ) =~ s|.*/||; >+ print <<USAGE; >+ >+$basename >+ Export patron informations in CSV format. >+ It prints to standard output. Use redirection to save CSV in a file. >+ >+Usage: >+$0 [--field=FIELD [--field=FIELD [...]]] [--show-header] >+$0 -h >+ >+ -f, --field=FIELD Field to export. It is repeatable and has to match >+ keys returned by the GetMemberDetails function. >+ If no field is specified, then all fields will be >+ exported. >+ -H, --show-header Print field names on first row >+ -h, --help Show this help >+ >+USAGE >+} >+ >+# Getting parameters >+my @fields; >+my $show_header; >+my $help; >+ >+GetOptions( >+ 'field|f=s' => \@fields, >+ 'show-header|H' => \$show_header, >+ 'help|h' => \$help >+) or print_usage, exit 1; >+ >+if ($help) { >+ print_usage; >+ exit; >+} >+ >+# Getting borrowers >+my $dbh = C4::Context->dbh; >+my $query = "SELECT borrowernumber FROM borrowers ORDER BY borrowernumber"; >+my $sth = $dbh->prepare($query); >+$sth->execute; >+ >+my $csv = Text::CSV->new( { binary => 1 } ); >+ >+# If the user did not specify any field to export, we assume he wants them all >+# We retrieve the first borrower informations to get field names >+my ($borrowernumber) = $sth->fetchrow_array; >+my $member = GetMemberDetails($borrowernumber); >+@fields = keys %$member unless (@fields); >+ >+if ($show_header) { >+ $csv->combine(@fields); >+ print $csv->string . "\n"; >+} >+ >+$csv->combine( >+ map { >+ ( defined $member->{$_} and !ref $member->{$_} ) >+ ? $member->{$_} >+ : '' >+ } @fields >+); >+die "Invalid character at borrower $borrowernumber: [" >+ . $csv->error_input . "]\n" >+ if ( !defined( $csv->string ) ); >+print $csv->string . "\n"; >+ >+while ( my $borrowernumber = $sth->fetchrow_array ) { >+ $member = GetMemberDetails($borrowernumber); >+ $csv->combine( >+ map { >+ ( defined $member->{$_} and !ref $member->{$_} ) >+ ? $member->{$_} >+ : '' >+ } @fields >+ ); >+ die "Invalid character at borrower $borrowernumber: [" >+ . $csv->error_input . "]\n" >+ if ( !defined( $csv->string ) ); >+ print $csv->string . "\n"; >+} >+ >-- >1.7.9.5
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 8376
:
10665
|
10672
| 11033