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>.
26 use Koha::Patrons::Import;
27 my $Import = Koha::Patrons::Import->new();
31 my $overwrite_cardnumber;
39 'c|confirm' => \$confirm,
40 'f|file=s' => \$csv_file,
41 'm|matchpoint=s' => \$matchpoint,
42 'd|default=s' => \%defaults,
43 'o|overwrite' => \$overwrite_cardnumber,
44 'p|preserve-extended-attributes' => \$ext_preserve,
45 'v|verbose+' => \$verbose,
49 pod2usage(1) if $help;
50 pod2usage(q|--file is required|) unless $csv_file;
51 pod2usage(q|--matchpoint is required|) unless $matchpoint;
53 warn "Running in dry-run mode, provide --confirm to apply the changes\n" unless $confirm;
56 open( $handle, "<", $csv_file ) or die $!;
58 my $return = $Import->import_patrons(
61 defaults => \%defaults,
62 matchpoint => $matchpoint,
63 overwrite_cardnumber => $overwrite_cardnumber,
64 preserve_extended_attributes => $ext_preserve,
69 my $feedback = $return->{feedback};
70 my $errors = $return->{errors};
71 my $imported = $return->{imported};
72 my $overwritten = $return->{overwritten};
73 my $alreadyindb = $return->{already_in_db};
74 my $invalid = $return->{invalid};
77 my $total = $imported + $alreadyindb + $invalid + $overwritten;
79 say "Import complete:";
80 say "Imported: $imported";
81 say "Overwritten: $overwritten";
82 say "Skipped: $alreadyindb";
83 say "Invalid: $invalid";
90 say Data::Dumper::Dumper( $errors );
95 say Data::Dumper::Dumper( $feedback );
100 import_patrons.pl - CLI script to import patrons data into Koha
104 import_patrons.pl --file /path/to/patrons.csv --matchpoint cardnumber --confirm [--default branchcode=MPL] [--overwrite] [--preserve-extended-attributes] [--verbose]
112 Prints a brief help message and exits
114 =item B<-c|--confirm>
116 Confirms you really want to import these patrons, otherwise prints this help
120 Path to the CSV file of patrons to import
122 =item B<-c|--matchpoint>
124 Field on which to match incoming patrons to existing patrons
126 =item B<-d|--default>
128 Set defaults to patron fields, repeatable e.g. --default branchcode=MPL --default categorycode=PT
130 =item B<-o|--overwrite>
132 Overwrite existing patrons with new data if a match is found
134 =item B<-p|--preserve-extended-attributes>
136 Retain extended patron attributes for existing patrons being overwritten
138 =item B<-v|--verbose>
142 Multiple -v options increase the verbosity
144 2 repetitions or above will report lines in error
146 3 repetitions or above will report feedback