Bug 11412: fix potential bulkmarcimport crash when searching for duplicates in author...
[koha.git] / misc / migration_tools / bulkmarcimport.pl
blob545e8182a8337927f8233177257b3233b62a2bad
1 #!/usr/bin/perl
2 # Import an iso2709 file into Koha 3
4 use strict;
5 use warnings;
6 #use diagnostics;
7 BEGIN {
8 # find Koha's Perl modules
9 # test carefully before changing this
10 use FindBin;
11 eval { require "$FindBin::Bin/../kohalib.pl" };
14 # Koha modules used
15 use MARC::File::USMARC;
16 use MARC::File::XML;
17 use MARC::Record;
18 use MARC::Batch;
19 use MARC::Charset;
21 use C4::Context;
22 use C4::Biblio;
23 use C4::Koha;
24 use C4::Debug;
25 use C4::Charset;
26 use C4::Items;
27 use YAML;
28 use Unicode::Normalize;
29 use Time::HiRes qw(gettimeofday);
30 use Getopt::Long;
31 use IO::File;
32 use Pod::Usage;
34 use open qw( :std :encoding(UTF-8) );
35 binmode( STDOUT, ":encoding(UTF-8)" );
36 my ( $input_marc_file, $number, $offset) = ('',0,0);
37 my ($version, $delete, $test_parameter, $skip_marc8_conversion, $char_encoding, $verbose, $commit, $fk_off,$format,$biblios,$authorities,$keepids,$match, $isbn_check, $logfile);
38 my ( $insert, $filters, $update, $all, $yamlfile, $authtypes );
39 my $cleanisbn = 1;
40 my ($sourcetag,$sourcesubfield,$idmapfl, $dedup_barcode);
41 my $framework = '';
43 $|=1;
45 GetOptions(
46 'commit:f' => \$commit,
47 'file:s' => \$input_marc_file,
48 'n:f' => \$number,
49 'o|offset:f' => \$offset,
50 'h' => \$version,
51 'd' => \$delete,
52 't|test' => \$test_parameter,
53 's' => \$skip_marc8_conversion,
54 'c:s' => \$char_encoding,
55 'v:s' => \$verbose,
56 'fk' => \$fk_off,
57 'm:s' => \$format,
58 'l:s' => \$logfile,
59 'k|keepids:s' => \$keepids,
60 'b|biblios' => \$biblios,
61 'a|authorities' => \$authorities,
62 'authtypes:s' => \$authtypes,
63 'filter=s@' => \$filters,
64 'insert' => \$insert,
65 'update' => \$update,
66 'all' => \$all,
67 'match=s@' => \$match,
68 'i|isbn' => \$isbn_check,
69 'x:s' => \$sourcetag,
70 'y:s' => \$sourcesubfield,
71 'idmap:s' => \$idmapfl,
72 'cleanisbn!' => \$cleanisbn,
73 'yaml:s' => \$yamlfile,
74 'dedupbarcode' => \$dedup_barcode,
75 'framework=s' => \$framework,
77 $biblios ||= !$authorities;
78 $insert ||= !$update;
80 if ($all) {
81 $insert = 1;
82 $update = 1;
85 if ($version || ($input_marc_file eq '')) {
86 pod2usage( -verbose => 2 );
87 exit;
90 my $dbh = C4::Context->dbh;
91 my $heading_fields=get_heading_fields();
93 if (defined $idmapfl) {
94 open(IDMAP,">$idmapfl") or die "cannot open $idmapfl \n";
97 if ((not defined $sourcesubfield) && (not defined $sourcetag)){
98 $sourcetag="910";
99 $sourcesubfield="a";
102 # save the CataloguingLog property : we don't want to log a bulkmarcimport. It will slow the import &
103 # will create problems in the action_logs table, that can't handle more than 1 entry per second per user.
104 my $CataloguingLog = C4::Context->preference('CataloguingLog');
105 $dbh->do("UPDATE systempreferences SET value=0 WHERE variable='CataloguingLog'");
107 if ($fk_off) {
108 $dbh->do("SET FOREIGN_KEY_CHECKS = 0");
112 if ($delete) {
113 if ($biblios){
114 print "deleting biblios\n";
115 $dbh->do("truncate biblio");
116 $dbh->do("truncate biblioitems");
117 $dbh->do("truncate items");
119 else {
120 print "deleting authorities\n";
121 $dbh->do("truncate auth_header");
123 $dbh->do("truncate zebraqueue");
128 if ($test_parameter) {
129 print "TESTING MODE ONLY\n DOING NOTHING\n===============\n";
132 my $marcFlavour = C4::Context->preference('marcflavour') || 'MARC21';
134 print "Characteristic MARC flavour: $marcFlavour\n" if $verbose;
135 my $starttime = gettimeofday;
136 my $batch;
137 my $fh = IO::File->new($input_marc_file); # don't let MARC::Batch open the file, as it applies the ':utf8' IO layer
138 if (defined $format && $format =~ /XML/i) {
139 # ugly hack follows -- MARC::File::XML, when used by MARC::Batch,
140 # appears to try to convert incoming XML records from MARC-8
141 # to UTF-8. Setting the BinaryEncoding key turns that off
142 # TODO: see what happens to ISO-8859-1 XML files.
143 # TODO: determine if MARC::Batch can be fixed to handle
144 # XML records properly -- it probably should be
145 # be using a proper push or pull XML parser to
146 # extract the records, not using regexes to look
147 # for <record>.*</record>.
148 $MARC::File::XML::_load_args{BinaryEncoding} = 'utf-8';
149 my $recordformat= ($marcFlavour eq "MARC21"?"USMARC":uc($marcFlavour));
150 #UNIMARC Authorities have a different way to manage encoding than UNIMARC biblios.
151 $recordformat=$recordformat."AUTH" if ($authorities and $marcFlavour ne "MARC21");
152 $MARC::File::XML::_load_args{RecordFormat} = $recordformat;
153 $batch = MARC::Batch->new( 'XML', $fh );
154 } else {
155 $batch = MARC::Batch->new( 'USMARC', $fh );
157 $batch->warnings_off();
158 $batch->strict_off();
159 my $i=0;
160 my $commitnum = $commit ? $commit : 50;
161 my $yamlhash;
163 # Skip file offset
164 if ( $offset ) {
165 print "Skipping file offset: $offset records\n";
166 $batch->next() while ($offset--);
169 my ($tagid,$subfieldid);
170 if ($authorities){
171 $tagid='001';
173 else {
174 ( $tagid, $subfieldid ) =
175 GetMarcFromKohaField( "biblio.biblionumber", $framework );
176 $tagid||="001";
179 # the SQL query to search on isbn
180 my $sth_isbn = $dbh->prepare("SELECT biblionumber,biblioitemnumber FROM biblioitems WHERE isbn=?");
182 $dbh->{AutoCommit} = 0;
183 my $loghandle;
184 if ($logfile){
185 $loghandle= IO::File->new($logfile,"w") ;
186 print $loghandle "id;operation;status\n";
188 RECORD: while ( ) {
189 my $record;
190 # get records
191 eval { $record = $batch->next() };
192 if ( $@ ) {
193 print "Bad MARC record $i: $@ skipped\n";
194 # FIXME - because MARC::Batch->next() combines grabbing the next
195 # blob and parsing it into one operation, a correctable condition
196 # such as a MARC-8 record claiming that it's UTF-8 can't be recovered
197 # from because we don't have access to the original blob. Note
198 # that the staging import can deal with this condition (via
199 # C4::Charset::MarcToUTF8Record) because it doesn't use MARC::Batch.
200 next;
202 # skip if we get an empty record (that is MARC valid, but will result in AddBiblio failure
203 last unless ( $record );
204 $i++;
205 print ".";
206 print "\n$i" unless $i % 100;
208 # transcode the record to UTF8 if needed & applicable.
209 if ($record->encoding() eq 'MARC-8' and not $skip_marc8_conversion) {
210 # FIXME update condition
211 my ($guessed_charset, $charset_errors);
212 ($record, $guessed_charset, $charset_errors) = MarcToUTF8Record($record, $marcFlavour.(($authorities and $marcFlavour ne "MARC21")?'AUTH':''));
213 if ($guessed_charset eq 'failed') {
214 warn "ERROR: failed to perform character conversion for record $i\n";
215 next RECORD;
218 SetUTF8Flag($record);
219 my $isbn;
220 # remove trailing - in isbn (only for biblios, of course)
221 if ($biblios && $cleanisbn) {
222 my $tag = $marcFlavour eq 'UNIMARC' ? '010' : '020';
223 my $field = $record->field($tag);
224 my $isbn = $field && $field->subfield('a');
225 if ( $isbn ) {
226 $isbn =~ s/-//g;
227 $field->update('a' => $isbn);
230 my $id;
231 # search for duplicates (based on Local-number)
232 my $originalid;
233 $originalid = GetRecordId( $record, $tagid, $subfieldid );
234 if ($match) {
235 require C4::Search;
236 my $query = build_query( $match, $record );
237 my $server = ( $authorities ? 'authorityserver' : 'biblioserver' );
238 $debug && warn $query;
239 my ( $error, $results, $totalhits ) = C4::Search::SimpleSearch( $query, 0, 3, [$server] );
240 die "unable to search the database for duplicates : $error" if ( defined $error );
241 $debug && warn "$query $server : $totalhits";
242 if ( $results && scalar(@$results) == 1 ) {
243 my $marcrecord = MARC::File::USMARC::decode( $results->[0] );
244 SetUTF8Flag($marcrecord);
245 $id = GetRecordId( $marcrecord, $tagid, $subfieldid );
246 if ( $authorities && $marcFlavour ) {
247 #Skip if authority in database is the same as the on in database
248 if ( $marcrecord->field('005') && $record->field('005') &&
249 $marcrecord->field('005')->data && $record->field('005')->data &&
250 $marcrecord->field('005')->data >= $record->field('005')->data ) {
251 if ($yamlfile) {
252 $yamlhash->{$originalid}->{'authid'} = $id;
254 # we recover all subfields of the heading authorities
255 my @subfields;
256 foreach my $field ( $marcrecord->field("2..") ) {
257 push @subfields, map { ( $_->[0] =~ /[a-z]/ ? $_->[1] : () ) } $field->subfields();
259 $yamlhash->{$originalid}->{'subfields'} = \@subfields;
261 next;
264 } elsif ( $results && scalar(@$results) > 1 ) {
265 $debug && warn "more than one match for $query";
266 } else {
267 $debug && warn "nomatch for $query";
270 if ($keepids && $originalid) {
271 my $storeidfield;
272 if ( length($keepids) == 3 ) {
273 $storeidfield = MARC::Field->new( $keepids, $originalid );
274 } else {
275 $storeidfield = MARC::Field->new( substr( $keepids, 0, 3 ), "", "", substr( $keepids, 3, 1 ), $originalid );
277 $record->insert_fields_ordered($storeidfield);
278 $record->delete_field( $record->field($tagid) );
280 foreach my $stringfilter (@$filters) {
281 if ( length($stringfilter) == 3 ) {
282 foreach my $field ( $record->field($stringfilter) ) {
283 $record->delete_field($field);
284 $debug && warn "removed : ", $field->as_string;
286 } elsif ($stringfilter =~ /([0-9]{3})([a-z0-9])(.*)/) {
287 my $removetag = $1;
288 my $removesubfield = $2;
289 my $removematch = $3;
290 if ( ( $removetag > "010" ) && $removesubfield ) {
291 foreach my $field ( $record->field($removetag) ) {
292 $field->delete_subfield( code => "$removesubfield", match => $removematch );
293 $debug && warn "Potentially removed : ", $field->subfield($removesubfield);
298 unless ($test_parameter) {
299 if ($authorities){
300 use C4::AuthoritiesMarc;
301 my $authtypecode=GuessAuthTypeCode($record, $heading_fields);
302 my $authid= ($id?$id:GuessAuthId($record));
303 if ($authid && GetAuthority($authid) && $update ){
304 ## Authority has an id and is in database : Replace
305 eval { ( $authid ) = ModAuthority($authid,$record, $authtypecode) };
306 if ($@){
307 warn "Problem with authority $authid Cannot Modify";
308 printlog({id=>$originalid||$id||$authid, op=>"edit",status=>"ERROR"}) if ($logfile);
310 else{
311 printlog({id=>$originalid||$id||$authid, op=>"edit",status=>"ok"}) if ($logfile);
314 elsif (defined $authid) {
315 ## An authid is defined but no authority in database : add
316 eval { ( $authid ) = AddAuthority($record,$authid, $authtypecode) };
317 if ($@){
318 warn "Problem with authority $authid Cannot Add ".$@;
319 printlog({id=>$originalid||$id||$authid, op=>"insert",status=>"ERROR"}) if ($logfile);
321 else{
322 printlog({id=>$originalid||$id||$authid, op=>"insert",status=>"ok"}) if ($logfile);
325 else {
326 ## True insert in database
327 eval { ( $authid ) = AddAuthority($record,"", $authtypecode) };
328 if ($@){
329 warn "Problem with authority $authid Cannot Add".$@;
330 printlog({id=>$originalid||$id||$authid, op=>"insert",status=>"ERROR"}) if ($logfile);
332 else{
333 printlog({id=>$originalid||$id||$authid, op=>"insert",status=>"ok"}) if ($logfile);
336 if ($yamlfile) {
337 $yamlhash->{$originalid}->{'authid'} = $authid;
338 my @subfields;
339 foreach my $field ( $record->field("2..") ) {
340 push @subfields, map { ( $_->[0] =~ /[a-z]/ ? $_->[1] : () ) } $field->subfields();
342 $yamlhash->{$originalid}->{'subfields'} = \@subfields;
345 else {
346 my ( $biblionumber, $biblioitemnumber, $itemnumbers_ref, $errors_ref );
347 $biblionumber = $id;
348 # check for duplicate, based on ISBN (skip it if we already have found a duplicate with match parameter
349 if (!$biblionumber && $isbn_check && $isbn) {
350 # warn "search ISBN : $isbn";
351 $sth_isbn->execute($isbn);
352 ($biblionumber,$biblioitemnumber) = $sth_isbn->fetchrow;
354 if (defined $idmapfl) {
355 if ($sourcetag < "010"){
356 if ($record->field($sourcetag)){
357 my $source = $record->field($sourcetag)->data();
358 printf(IDMAP "%s|%s\n",$source,$biblionumber);
360 } else {
361 my $source=$record->subfield($sourcetag,$sourcesubfield);
362 printf(IDMAP "%s|%s\n",$source,$biblionumber);
365 # create biblio, unless we already have it ( either match or isbn )
366 if ($biblionumber) {
367 eval{$biblioitemnumber=GetBiblioData($biblionumber)->{biblioitemnumber};};
368 if ($update) {
369 eval { ( $biblionumber, $biblioitemnumber ) = ModBiblio( $record, $biblionumber, GetFrameworkcode($biblionumber) ) };
370 if ($@) {
371 warn "ERROR: Edit biblio $biblionumber failed: $@\n";
372 printlog( { id => $id || $originalid || $biblionumber, op => "update", status => "ERROR" } ) if ($logfile);
373 next RECORD;
374 } else {
375 printlog( { id => $id || $originalid || $biblionumber, op => "update", status => "ok" } ) if ($logfile);
377 } else {
378 printlog( { id => $id || $originalid || $biblionumber, op => "insert", status => "warning : already in database" } ) if ($logfile);
380 } else {
381 if ($insert) {
382 eval { ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '', { defer_marc_save => 1 } ) };
383 if ($@) {
384 warn "ERROR: Adding biblio $biblionumber failed: $@\n";
385 printlog( { id => $id || $originalid || $biblionumber, op => "insert", status => "ERROR" } ) if ($logfile);
386 next RECORD;
387 } else {
388 printlog( { id => $id || $originalid || $biblionumber, op => "insert", status => "ok" } ) if ($logfile);
390 } else {
391 printlog( { id => $id || $originalid || $biblionumber, op => "update", status => "warning : not in database" } ) if ($logfile);
394 eval { ( $itemnumbers_ref, $errors_ref ) = AddItemBatchFromMarc( $record, $biblionumber, $biblioitemnumber, '' ); };
395 my $error_adding = $@;
396 # Work on a clone so that if there are real errors, we can maybe
397 # fix them up later.
398 my $clone_record = $record->clone();
399 C4::Biblio::_strip_item_fields($clone_record, '');
400 # This sets the marc fields if there was an error, and also calls
401 # defer_marc_save.
402 ModBiblioMarc( $clone_record, $biblionumber, $framework );
403 if ( $error_adding ) {
404 warn "ERROR: Adding items to bib $biblionumber failed: $error_adding";
405 printlog({id=>$id||$originalid||$biblionumber, op=>"insertitem",status=>"ERROR"}) if ($logfile);
406 # if we failed because of an exception, assume that
407 # the MARC columns in biblioitems were not set.
408 next RECORD;
410 else{
411 printlog({id=>$id||$originalid||$biblionumber, op=>"insert",status=>"ok"}) if ($logfile);
413 if ($dedup_barcode && grep { exists $_->{error_code} && $_->{error_code} eq 'duplicate_barcode' } @$errors_ref) {
414 # Find the record called 'barcode'
415 my ($tag, $sub) = C4::Biblio::GetMarcFromKohaField('items.barcode', $framework);
416 # Now remove any items that didn't have a duplicate_barcode error,
417 # erase the barcodes on items that did, and re-add those items.
418 my %dupes;
419 foreach my $i (0 .. $#{$errors_ref}) {
420 my $ref = $errors_ref->[$i];
421 if ($ref && ($ref->{error_code} eq 'duplicate_barcode')) {
422 $dupes{$ref->{item_sequence}} = 1;
423 # Delete the error message because we're going to
424 # retry this one.
425 delete $errors_ref->[$i];
428 my $seq = 0;
429 foreach my $field ($record->field($tag)) {
430 $seq++;
431 if ($dupes{$seq}) {
432 # Here we remove the barcode
433 $field->delete_subfield(code => $sub);
434 } else {
435 # otherwise we delete the field because we don't want
436 # two of them
437 $record->delete_fields($field);
440 # Now re-add the record as before, adding errors to the prev list
441 my $more_errors;
442 eval { ( $itemnumbers_ref, $more_errors ) = AddItemBatchFromMarc( $record, $biblionumber, $biblioitemnumber, '' ); };
443 if ( $@ ) {
444 warn "ERROR: Adding items to bib $biblionumber failed: $@\n";
445 printlog({id=>$id||$originalid||$biblionumber, op=>"insertitem",status=>"ERROR"}) if ($logfile);
446 # if we failed because of an exception, assume that
447 # the MARC columns in biblioitems were not set.
448 ModBiblioMarc( $record, $biblionumber, $framework );
449 next RECORD;
450 } else {
451 printlog({id=>$id||$originalid||$biblionumber, op=>"insert",status=>"ok"}) if ($logfile);
453 push @$errors_ref, @{ $more_errors };
455 if ($#{ $errors_ref } > -1) {
456 report_item_errors($biblionumber, $errors_ref);
458 $yamlhash->{$originalid} = $biblionumber if ($yamlfile);
460 $dbh->commit() if (0 == $i % $commitnum);
462 last if $i == $number;
464 $dbh->commit();
465 $dbh->{AutoCommit} = 1;
468 if ($fk_off) {
469 $dbh->do("SET FOREIGN_KEY_CHECKS = 1");
472 # restore CataloguingLog
473 $dbh->do("UPDATE systempreferences SET value=$CataloguingLog WHERE variable='CataloguingLog'");
475 my $timeneeded = gettimeofday - $starttime;
476 print "\n$i MARC records done in $timeneeded seconds\n";
477 if ($logfile){
478 print $loghandle "file : $input_marc_file\n";
479 print $loghandle "$i MARC records done in $timeneeded seconds\n";
480 $loghandle->close;
482 if ($yamlfile) {
483 open my $yamlfileout, q{>}, "$yamlfile" or die "cannot open $yamlfile \n";
484 print $yamlfileout Dump($yamlhash);
486 exit 0;
488 sub GetRecordId{
489 my $marcrecord=shift;
490 my $tag=shift;
491 my $subfield=shift;
492 my $id;
493 if ($tag lt "010"){
494 return $marcrecord->field($tag)->data() if $marcrecord->field($tag);
496 elsif ($subfield){
497 if ($marcrecord->field($tag)){
498 return $marcrecord->subfield($tag,$subfield);
501 return $id;
503 sub build_query {
504 my $match = shift;
505 my $record=shift;
506 my @searchstrings;
507 foreach my $matchingpoint (@$match){
508 my $string = build_simplequery($matchingpoint,$record);
509 push @searchstrings,$string if (length($string)>0);
511 my $QParser;
512 $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
513 my $op;
514 if ($QParser) {
515 $op = '&&';
516 } else {
517 $op = 'and';
519 return join(" $op ",@searchstrings);
521 sub build_simplequery {
522 my $element=shift;
523 my $record=shift;
524 my @searchstrings;
525 my ($index,$recorddata)=split /,/,$element;
526 if ($recorddata=~/(\d{3})(.*)/) {
527 my ($tag,$subfields) =($1,$2);
528 foreach my $field ($record->field($tag)){
529 if (length($field->as_string("$subfields"))>0){
530 push @searchstrings,"$index:\"".$field->as_string("$subfields")."\"";
534 my $QParser;
535 $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
536 my $op;
537 if ($QParser) {
538 $op = '&&';
539 } else {
540 $op = 'and';
542 return join(" $op ",@searchstrings);
544 sub report_item_errors {
545 my $biblionumber = shift;
546 my $errors_ref = shift;
548 foreach my $error (@{ $errors_ref }) {
549 next if !$error;
550 my $msg = "Item not added (bib $biblionumber, item tag #$error->{'item_sequence'}, barcode $error->{'item_barcode'}): ";
551 my $error_code = $error->{'error_code'};
552 $error_code =~ s/_/ /g;
553 $msg .= "$error_code $error->{'error_information'}";
554 print $msg, "\n";
557 sub printlog{
558 my $logelements=shift;
559 print $loghandle join( ";", map { defined $_ ? $_ : "" } @$logelements{qw<id op status>} ), "\n";
561 sub get_heading_fields{
562 my $headingfields;
563 if ($authtypes){
564 $headingfields=YAML::LoadFile($authtypes);
565 $headingfields={C4::Context->preference('marcflavour')=>$headingfields};
566 $debug && warn YAML::Dump($headingfields);
568 unless ($headingfields){
569 $headingfields=$dbh->selectall_hashref("SELECT auth_tag_to_report, authtypecode from auth_types",'auth_tag_to_report',{Slice=>{}});
570 $headingfields={C4::Context->preference('marcflavour')=>$headingfields};
572 return $headingfields;
575 =head1 NAME
577 bulkmarcimport.pl - Import bibliographic/authority records into Koha
579 =head1 USAGE
581 $ export KOHA_CONF=/etc/koha.conf
582 $ perl misc/migration_tools/bulkmarcimport.pl -d -commit 1000 \\
583 -file /home/jmf/koha.mrc -n 3000
585 =head1 WARNING
587 Don't use this script before you've entered and checked your MARC parameters
588 tables twice (or more!). Otherwise, the import won't work correctly and you
589 will get invalid data.
591 =head1 DESCRIPTION
593 =over
595 =item B<-h>
597 This version/help screen
599 =item B<-b, -biblios>
601 Type of import: bibliographic records
603 =item B<-a, -authorities>
605 Type of import: authority records
607 =item B<-file>=I<FILE>
609 The I<FILE> to import
611 =item B<-v>
613 Verbose mode. 1 means "some infos", 2 means "MARC dumping"
615 =item B<-fk>
617 Turn off foreign key checks during import.
619 =item B<-n>=I<NUMBER>
621 The I<NUMBER> of records to import. If missing, all the file is imported
623 =item B<-o, -offset>=I<NUMBER>
625 File offset before importing, ie I<NUMBER> of records to skip.
627 =item B<-commit>=I<NUMBER>
629 The I<NUMBER> of records to wait before performing a 'commit' operation
631 =item B<-l>
633 File logs actions done for each record and their status into file
635 =item B<-t, -test>
637 Test mode: parses the file, saying what he would do, but doing nothing.
639 =item B<-s>
641 Skip automatic conversion of MARC-8 to UTF-8. This option is provided for
642 debugging.
644 =item B<-c>=I<CHARACTERISTIC>
646 The I<CHARACTERISTIC> MARC flavour. At the moment, only I<MARC21> and
647 I<UNIMARC> are supported. MARC21 by default.
649 =item B<-d>
651 Delete EVERYTHING related to biblio in koha-DB before import. Tables: biblio,
652 biblioitems, items
654 =item B<-m>=I<FORMAT>
656 Input file I<FORMAT>: I<MARCXML> or I<ISO2709> (defaults to ISO2709)
658 =item B<-authtypes>
660 file yamlfile with authoritiesTypes and distinguishable record field in order
661 to store the correct authtype
663 =item B<-yaml>
665 yaml file format a yaml file with ids
667 =item B<-filter>
669 list of fields that will not be imported. Can be any from 000 to 999 or field,
670 subfield and subfield's matching value such as 200avalue
672 =item B<-insert>
674 if set, only insert when possible
676 =item B<-update>
678 if set, only updates (any biblio should have a matching record)
680 =item B<-all>
682 if set, do whatever is required
684 =item B<-k, -keepids>=<FIELD>
686 Field store ids in I<FIELD> (usefull for authorities, where 001 contains the
687 authid for Koha, that can contain a very valuable info for authorities coming
688 from LOC or BNF. useless for biblios probably)
690 =item B<-match>=<FIELD>
692 I<FIELD> matchindex,fieldtomatch matchpoint to use to deduplicate fieldtomatch
693 can be either 001 to 999 or field and list of subfields as such 100abcde
695 =item B<-i,-isbn>
697 If set, a search will be done on isbn, and, if the same isbn is found, the
698 biblio is not added. It's another method to deduplicate. B<-match> & B<-isbn>
699 can be both set.
701 =item B<-cleanisbn>
703 Clean ISBN fields from entering biblio records, ie removes hyphens. By default,
704 ISBN are cleaned. --nocleanisbn will keep ISBN unchanged.
706 =item B<-x>=I<TAG>
708 Source bib I<TAG> for reporting the source bib number
710 =item B<-y>=I<SUBFIELD>
712 Source I<SUBFIELD> for reporting the source bib number
714 =item B<-idmap>=I<FILE>
716 I<FILE> for the koha bib and source id
718 =item B<-keepids>
720 Store ids in 009 (usefull for authorities, where 001 contains the authid for
721 Koha, that can contain a very valuable info for authorities coming from LOC or
722 BNF. useless for biblios probably)
724 =item B<-dedupbarcode>
726 If set, whenever a duplicate barcode is detected, it is removed and the attempt
727 to add the record is retried, thereby giving the record a blank barcode. This
728 is useful when something has set barcodes to be a biblio ID, or similar
729 (usually other software.)
731 =item B<-framework>
733 This is the code for the framework that the requested records will have attached
734 to them when they are created. If not specified, then the default framework
735 will be used.
737 =back
739 =cut