projects
/
koha_fer
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Bug 10720: fix issue that prevented use of HTML tags in overdue notices
[koha_fer]
/
misc
/
export_borrowers.pl
diff --git
a/misc/export_borrowers.pl
b/misc/export_borrowers.pl
index
c4b3e40
..
7d3ce47
100755
(executable)
--- a/
misc/export_borrowers.pl
+++ b/
misc/export_borrowers.pl
@@
-37,14
+37,23
@@
$basename
It prints to standard output. Use redirection to save CSV in a file.
Usage:
It prints to standard output. Use redirection to save CSV in a file.
Usage:
-$0 [--field=FIELD [--field=FIELD [...]]] [--s
how-header
]
+$0 [--field=FIELD [--field=FIELD [...]]] [--s
eparator=CHAR] [--show-header] [--where=CONDITION
]
$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.
$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.
+ -s, --separator=CHAR This character will be used to separate fields.
+ Some characters like | or ; will need to be escaped
+ in the parameter setting, like -s=\\| or -s=\\;
+ If no separator is specifield, a comma will be used.
-H, --show-header Print field names on first row
-H, --show-header Print field names on first row
+ -w, --where=CONDITION Condition to filter borrowers to export
+ (SQL where clause).
+ CONDITION must be enclosed by double quotes and
+ if needed, where value by single quotes.
+ example : --where "surname='De Lattre'"
-h, --help Show this help
USAGE
-h, --help Show this help
USAGE
@@
-52,12
+61,16
@@
USAGE
# Getting parameters
my @fields;
# Getting parameters
my @fields;
+my $separator;
my $show_header;
my $show_header;
+my $where;
my $help;
GetOptions(
'field|f=s' => \@fields,
my $help;
GetOptions(
'field|f=s' => \@fields,
+ 'separator|s=s' => \$separator,
'show-header|H' => \$show_header,
'show-header|H' => \$show_header,
+ 'where|w=s' => \$where,
'help|h' => \$help
) or print_usage, exit 1;
'help|h' => \$help
) or print_usage, exit 1;
@@
-68,15
+81,17
@@
if ($help) {
# Getting borrowers
my $dbh = C4::Context->dbh;
# Getting borrowers
my $dbh = C4::Context->dbh;
-my $query = "SELECT borrowernumber FROM borrowers ORDER BY borrowernumber";
+my $query = "SELECT borrowernumber FROM borrowers";
+$query .= " WHERE $where" if ($where);
+$query .= " ORDER BY borrowernumber";
my $sth = $dbh->prepare($query);
$sth->execute;
my $sth = $dbh->prepare($query);
$sth->execute;
-my $csv = Text::CSV->new( { binary => 1 } );
+my $csv = Text::CSV->new( {
sep_char => $separator,
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
# 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 ($borrowernumber) = $sth->fetchrow_array
or die "No borrower to export"
;
my $member = GetMemberDetails($borrowernumber);
@fields = keys %$member unless (@fields);
my $member = GetMemberDetails($borrowernumber);
@fields = keys %$member unless (@fields);