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>.
25 use Koha
::Patrons
::Import
;
26 my $Import = Koha
::Patrons
::Import
->new();
30 my $overwrite_cardnumber;
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-attributes' => \
$ext_preserve,
44 'v|verbose+' => \
$verbose,
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;
55 open( $handle, "<", $csv_file ) or die $!;
57 my $return = $Import->import_patrons(
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
};
75 my $total = $imported + $alreadyindb + $invalid + $overwritten;
77 say "Import complete:";
78 say "Imported: $imported";
79 say "Overwritten: $overwritten";
80 say "Skipped: $alreadyindb";
81 say "Invalid: $invalid";
88 say Data
::Dumper
::Dumper
( $errors );
93 say Data
::Dumper
::Dumper
( $feedback );
98 import_patrons.pl - CLI script to import patrons data into Koha
102 import_patrons.pl --file /path/to/patrons.csv --matchpoint cardnumber --confirm [--default branchcode=MPL] [--overwrite] [--preserve-extended-attributes] [--verbose]
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
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-attributes>
134 Retain extended patron attributes for existing patrons being overwritten
136 =item B<-v|--verbose>