Bug 4078: Pass with_symbol to module
[koha.git] / misc / import_patrons.pl
blob5a7916b62015db1e0165cafd5b069dcdcb3ead9a
1 #!/usr/bin/perl
3 # Parts copyright 2014 ByWater Solutions
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Modern::Perl;
22 use Getopt::Long;
23 use Pod::Usage;
25 use Koha::Patrons::Import;
26 my $Import = Koha::Patrons::Import->new();
28 my $csv_file;
29 my $matchpoint;
30 my $overwrite_cardnumber;
31 my %defaults;
32 my $ext_preserve = 0;
33 my $confirm;
34 my $verbose = 0;
35 my $help;
37 GetOptions(
38 'c|confirm' => \$confirm,
39 'f|file=s' => \$csv_file,
40 'm|matchpoint=s' => \$matchpoint,
41 'd|default=s' => \%defaults,
42 'o|overwrite' => \$overwrite_cardnumber,
43 'p|preserve-extended-atributes' => \$ext_preserve,
44 'v|verbose+' => \$verbose,
45 'h|help|?' => \$help,
46 ) or pod2usage(2);
48 pod2usage(1) if $help;
49 pod2usage(q|--file is required|) unless $csv_file;
50 pod2usage(q|--matchpoint is required|) unless $matchpoint;
52 warn "Running in dry-run mode, provide --confirm to apply the changes\n" unless $confirm;
54 my $handle;
55 open( $handle, "<", $csv_file ) or die $!;
57 my $return = $Import->import_patrons(
59 file => $handle,
60 defaults => \%defaults,
61 matchpoint => $matchpoint,
62 overwrite_cardnumber => $overwrite_cardnumber,
63 preserve_extended_attributes => $ext_preserve,
67 my $feedback = $return->{feedback};
68 my $errors = $return->{errors};
69 my $imported = $return->{imported};
70 my $overwritten = $return->{overwritten};
71 my $alreadyindb = $return->{already_in_db};
72 my $invalid = $return->{invalid};
74 if ($verbose) {
75 my $total = $imported + $alreadyindb + $invalid + $overwritten;
76 say q{};
77 say "Import complete:";
78 say "Imported: $imported";
79 say "Overwritten: $overwritten";
80 say "Skipped: $alreadyindb";
81 say "Invalid: $invalid";
82 say "Total: $total";
83 say q{};
86 if ($verbose > 1 ) {
87 say "Errors:";
88 say Data::Dumper::Dumper( $errors );
91 if ($verbose > 2 ) {
92 say "Feedback:";
93 say Data::Dumper::Dumper( $feedback );
96 =head1 NAME
98 import_patrons.pl - CLI script to import patrons data into Koha
100 =head1 SYNOPSIS
102 import_patrons.pl --file /path/to/patrons.csv --matchpoint cardnumber --confirm [--default branchcode=MPL] [--overwrite] [--preserve-extended-atributes] [--verbose]
104 =head1 OPTIONS
106 =over 8
108 =item B<-h|--help>
110 Prints a brief help message and exits
112 =item B<-c|--confirm>
114 Confirms you really want to import these patrons, otherwise prints this help
116 =item B<-f|--file>
118 Path to the CSV file of patrons to import
120 =item B<-c|--matchpoint>
122 Field on which to match incoming patrons to existing patrons
124 =item B<-d|--default>
126 Set defaults to patron fields, repeatable e.g. --default branchcode=MPL --default categorycode=PT
128 =item B<-o|--overwrite>
130 Overwrite existing patrons with new data if a match is found
132 =item B<-p|--preserve-extended-atributes>
134 Retain extended patron attributes for existing patrons being overwritten
136 =item B<-v|--verbose>
138 Be verbose
140 =back
142 =cut