+print "\n$i MARC records done in $timeneeded seconds\n";
+if ($logfile){
+ print $loghandle "file : $input_marc_file\n";
+ print $loghandle "$i MARC records done in $timeneeded seconds\n";
+ $loghandle->close;
+}
+exit 0;
+
+sub GetRecordId{
+ my $marcrecord=shift;
+ my $tag=shift;
+ my $subfield=shift;
+ my $id;
+ if ($tag lt "010"){
+ return $marcrecord->field($tag)->data() if $marcrecord->field($tag);
+ }
+ elsif ($subfield){
+ if ($marcrecord->field($tag)){
+ return $marcrecord->subfield($tag,$subfield);
+ }
+ }
+ return $id;
+}
+sub build_query {
+ my $match = shift;
+ my $record=shift;
+ my @searchstrings;
+ foreach my $matchingpoint (@$match){
+ my $string = build_simplequery($matchingpoint,$record);
+ push @searchstrings,$string if (length($string)>0);
+ }
+ return join(" and ",@searchstrings);
+}
+sub build_simplequery {
+ my $element=shift;
+ my $record=shift;
+ my ($index,$recorddata)=split /,/,$element;
+ my ($tag,$subfields) =($1,$2) if ($recorddata=~/(\d{3})(.*)/);
+ my @searchstrings;
+ foreach my $field ($record->field($tag)){
+ if (length($field->as_string("$subfields"))>0){
+ push @searchstrings,"$index,wrdl=\"".$field->as_string("$subfields")."\"";
+ }
+ }
+ return join(" and ",@searchstrings);
+}
+sub report_item_errors {
+ my $biblionumber = shift;
+ my $errors_ref = shift;
+
+ foreach my $error (@{ $errors_ref }) {
+ my $msg = "Item not added (bib $biblionumber, item tag #$error->{'item_sequence'}, barcode $error->{'item_barcode'}): ";
+ my $error_code = $error->{'error_code'};
+ $error_code =~ s/_/ /g;
+ $msg .= "$error_code $error->{'error_information'}";
+ print $msg, "\n";
+ }
+}
+sub printlog{
+ my $logelements=shift;
+ print $loghandle join (";",@$logelements{qw<id op status>}),"\n";
+}
+
+
+=head1 NAME
+
+bulkmarcimport.pl - Import bibliographic/authority records into Koha
+
+=head1 USAGE
+
+ $ export KOHA_CONF=/etc/koha.conf
+ $ perl misc/migration_tools/bulkmarcimport.pl -d -commit 1000 \\
+ -file /home/jmf/koha.mrc -n 3000
+
+=head1 WARNING
+
+Don't use this script before you've entered and checked your MARC parameters
+tables twice (or more!). Otherwise, the import won't work correctly and you
+will get invalid data.
+
+=head1 DESCRIPTION
+
+=over
+
+=item B<-h>
+
+This version/help screen
+
+=item B<-b, -biblios>
+
+Type of import: bibliographic records
+
+=item B<-a, -authorities>
+
+Type of import: authority records
+
+=item B<-file>=I<FILE>
+
+The I<FILE> to import
+
+=item B<-v>
+
+Verbose mode. 1 means "some infos", 2 means "MARC dumping"
+
+=item B<-fk>
+
+Turn off foreign key checks during import.
+
+=item B<-n>=I<NUMBER>
+
+The I<NUMBER> of records to import. If missing, all the file is imported
+
+=item B<-o, -offset>=I<NUMBER>
+
+File offset before importing, ie I<NUMBER> of records to skip.
+
+=item B<-commit>=I<NUMBER>
+
+The I<NUMBER> of records to wait before performing a 'commit' operation
+
+=item B<-l>
+
+File logs actions done for each record and their status into file
+
+=item B<-t>
+
+Test mode: parses the file, saying what he would do, but doing nothing.
+
+=item B<-s>
+
+Skip automatic conversion of MARC-8 to UTF-8. This option is provided for
+debugging.
+
+=item B<-c>=I<CHARACTERISTIC>
+
+The I<CHARACTERISTIC> MARC flavour. At the moment, only I<MARC21> and
+I<UNIMARC> are supported. MARC21 by default.
+
+=item B<-d>
+
+Delete EVERYTHING related to biblio in koha-DB before import. Tables: biblio,
+biblioitems, items
+
+=item B<-m>=I<FORMAT>
+
+Input file I<FORMAT>: I<MARCXML> or I<ISO2709> (defaults to ISO2709)
+
+=item B<-k, -keepids>=<FIELD>
+
+Field store ids in I<FIELD> (usefull for authorities, where 001 contains the
+authid for Koha, that can contain a very valuable info for authorities coming
+from LOC or BNF. useless for biblios probably)
+
+=item B<-match>=<FIELD>
+
+I<FIELD> matchindex,fieldtomatch matchpoint to use to deduplicate fieldtomatch
+can be either 001 to 999 or field and list of subfields as such 100abcde
+
+=item B<-i,-isbn>
+
+If set, a search will be done on isbn, and, if the same isbn is found, the
+biblio is not added. It's another method to deduplicate. B<-match> & B<-isbn>
+can be both set.
+
+=item B<-cleanisbn>
+
+Clean ISBN fields from entering biblio records, ie removes hyphens. By default,
+ISBN are cleaned. --nocleanisbn will keep ISBN unchanged.
+
+=item B<-x>=I<TAG>
+
+Source bib I<TAG> for reporting the source bib number
+
+=item B<-y>=I<SUBFIELD>
+
+Source I<SUBFIELD> for reporting the source bib number
+
+=item B<-idmap>=I<FILE>
+
+I<FILE> for the koha bib and source id
+
+=item B<-keepids>
+
+Store ids in 009 (usefull for authorities, where 001 contains the authid for
+Koha, that can contain a very valuable info for authorities coming from LOC or
+BNF. useless for biblios probably)
+
+=back
+
+=cut
+