View | Details | Raw Unified | Return to bug 9045
Collapse All | Expand All

(-)a/misc/export_borrowers.pl (-4 / +15 lines)
Lines 37-50 $basename Link Here
37
    It prints to standard output. Use redirection to save CSV in a file.
37
    It prints to standard output. Use redirection to save CSV in a file.
38
38
39
Usage:
39
Usage:
40
$0 [--field=FIELD [--field=FIELD [...]]] [--show-header]
40
$0 [--field=FIELD [--field=FIELD [...]]] [--separator=CHAR] [--show-header] [--where=CONDITION]
41
$0 -h
41
$0 -h
42
42
43
    -f, --field=FIELD       Field to export. It is repeatable and has to match
43
    -f, --field=FIELD       Field to export. It is repeatable and has to match
44
                            keys returned by the GetMemberDetails function.
44
                            keys returned by the GetMemberDetails function.
45
                            If no field is specified, then all fields will be
45
                            If no field is specified, then all fields will be
46
                            exported.
46
                            exported.
47
    -s, --separator=CHAR    This character will be used to separate fields.
48
                            Some characters like | or ; will need to be escaped
49
                            in the parameter setting, like -s=\\| or -s=\\;
50
                            If no separator is specifield, a comma will be used.
47
    -H, --show-header       Print field names on first row
51
    -H, --show-header       Print field names on first row
52
    -w, --where=CONDITION   Condition to filter borrowers to export
53
                            (SQL where clause)
48
    -h, --help              Show this help
54
    -h, --help              Show this help
49
55
50
USAGE
56
USAGE
Lines 52-63 USAGE Link Here
52
58
53
# Getting parameters
59
# Getting parameters
54
my @fields;
60
my @fields;
61
my $separator;
55
my $show_header;
62
my $show_header;
63
my $where;
56
my $help;
64
my $help;
57
65
58
GetOptions(
66
GetOptions(
59
    'field|f=s'     => \@fields,
67
    'field|f=s'     => \@fields,
68
    'separator|s=s' => \$separator,
60
    'show-header|H' => \$show_header,
69
    'show-header|H' => \$show_header,
70
    'where|w=s'       => \$where,
61
    'help|h'        => \$help
71
    'help|h'        => \$help
62
) or print_usage, exit 1;
72
) or print_usage, exit 1;
63
73
Lines 68-78 if ($help) { Link Here
68
78
69
# Getting borrowers
79
# Getting borrowers
70
my $dbh   = C4::Context->dbh;
80
my $dbh   = C4::Context->dbh;
71
my $query = "SELECT borrowernumber FROM borrowers ORDER BY borrowernumber";
81
my $query = "SELECT borrowernumber FROM borrowers";
82
$query .= " WHERE $where" if ($where);
83
$query .= " ORDER BY borrowernumber";
72
my $sth   = $dbh->prepare($query);
84
my $sth   = $dbh->prepare($query);
73
$sth->execute;
85
$sth->execute;
74
86
75
my $csv = Text::CSV->new( { binary => 1 } );
87
my $csv = Text::CSV->new( { sep_char => $separator, binary => 1 } );
76
88
77
# If the user did not specify any field to export, we assume he wants them all
89
# If the user did not specify any field to export, we assume he wants them all
78
# We retrieve the first borrower informations to get field names
90
# We retrieve the first borrower informations to get field names
79
- 

Return to bug 9045