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>.
24 use Koha::Patrons::Import;
25 my $Import = Koha::Patrons::Import->new();
29 my $overwrite_cardnumber;
37 'c|confirm' => \$confirm,
38 'f|file=s' => \$csv_file,
39 'm|matchpoint=s' => \$matchpoint,
40 'd|default=s' => \%defaults,
41 'o|overwrite' => \$overwrite_cardnumber,
42 'p|preserve-extended-atributes' => \$ext_preserve,
43 'v|verbose+' => \$verbose,
47 print_help() if ( $help || !$csv_file || !$matchpoint || !$confirm );
50 open( $handle, "<", $csv_file ) or die $!;
52 my $return = $Import->import_patrons(
55 defaults => \%defaults,
56 matchpoint => $matchpoint,
57 overwrite_cardnumber => $overwrite_cardnumber,
58 preserve_extended_attributes => $ext_preserve,
62 my $feedback = $return->{feedback};
63 my $errors = $return->{errors};
64 my $imported = $return->{imported};
65 my $overwritten = $return->{overwritten};
66 my $alreadyindb = $return->{already_in_db};
67 my $invalid = $return->{invalid};
70 my $total = $imported + $alreadyindb + $invalid + $overwritten;
72 say "Import complete:";
73 say "Imported: $imported";
74 say "Overwritten: $overwritten";
75 say "Skipped: $alreadyindb";
76 say "Invalid: $invalid";
83 say Data::Dumper::Dumper( $errors );
88 say Data::Dumper::Dumper( $feedback );
93 import_patrons.pl -c /path/to/patrons.csv -m cardnumber
94 -c --confirm Confirms you really want to import these patrons, otherwise prints this help
95 -f --file Path to the CSV file of patrons to import
96 -m --matchpoint Field on which to match incoming patrons to existing patrons
97 -d --default Set defaults to patron fields, repeatable e.g. --default branchcode=MPL --default categorycode=PT
98 -p --preserve-extended-atributes Retain extended patron attributes for existing patrons being overwritten
99 -o --overwrite Overwrite existing patrons with new data if a match is found
100 -v --verbose Be verbose