View | Details | Raw Unified | Return to bug 6199
Collapse All | Expand All

(-)a/C4/Items.pm (-1 / +4 lines)
Lines 300-306 Sequence number of original item tag in the MARC record. Link Here
300
Item barcode, provide to assist in the construction of
300
Item barcode, provide to assist in the construction of
301
useful error messages.
301
useful error messages.
302
302
303
=item error_condition
303
=item error_code
304
304
305
Code representing the error condition.  Can be 'duplicate_barcode',
305
Code representing the error condition.  Can be 'duplicate_barcode',
306
'invalid_homebranch', or 'invalid_holdingbranch'.
306
'invalid_homebranch', or 'invalid_holdingbranch'.
Lines 320-325 sub AddItemBatchFromMarc { Link Here
320
    my @errors = ();
320
    my @errors = ();
321
    my $dbh = C4::Context->dbh;
321
    my $dbh = C4::Context->dbh;
322
322
323
    # We modify the record, so lets work on a clone so we don't change the
324
    # original.
325
    $record = $record->clone();
323
    # loop through the item tags and start creating items
326
    # loop through the item tags and start creating items
324
    my @bad_item_fields = ();
327
    my @bad_item_fields = ();
325
    my ($itemtag, $itemsubfield) = &GetMarcFromKohaField("items.itemnumber",'');
328
    my ($itemtag, $itemsubfield) = &GetMarcFromKohaField("items.itemnumber",'');
(-)a/misc/migration_tools/bulkmarcimport.pl (-3 / +54 lines)
Lines 33-39 use Pod::Usage; Link Here
33
binmode(STDOUT, ":utf8");
33
binmode(STDOUT, ":utf8");
34
my ( $input_marc_file, $number, $offset) = ('',0,0);
34
my ( $input_marc_file, $number, $offset) = ('',0,0);
35
my ($version, $delete, $test_parameter, $skip_marc8_conversion, $char_encoding, $verbose, $commit, $fk_off,$format,$biblios,$authorities,$keepids,$match, $isbn_check, $logfile);
35
my ($version, $delete, $test_parameter, $skip_marc8_conversion, $char_encoding, $verbose, $commit, $fk_off,$format,$biblios,$authorities,$keepids,$match, $isbn_check, $logfile);
36
my ($sourcetag,$sourcesubfield,$idmapfl);
36
my ($sourcetag,$sourcesubfield,$idmapfl, $dedup_barcode);
37
37
38
$|=1;
38
$|=1;
39
39
Lines 59-64 GetOptions( Link Here
59
    'x:s' => \$sourcetag,
59
    'x:s' => \$sourcetag,
60
    'y:s' => \$sourcesubfield,
60
    'y:s' => \$sourcesubfield,
61
    'idmap:s' => \$idmapfl,
61
    'idmap:s' => \$idmapfl,
62
    'dedupbarcode' => \$dedup_barcode,
62
);
63
);
63
$biblios=!$authorities||$biblios;
64
$biblios=!$authorities||$biblios;
64
65
Lines 344-349 RECORD: while ( ) { Link Here
344
 			else{
345
 			else{
345
				printlog({id=>$id||$originalid||$biblionumber, op=>"insert",status=>"ok"}) if ($logfile);
346
				printlog({id=>$id||$originalid||$biblionumber, op=>"insert",status=>"ok"}) if ($logfile);
346
			}
347
			}
348
			my $clone_record = $record->clone();
347
            eval { ( $itemnumbers_ref, $errors_ref ) = AddItemBatchFromMarc( $record, $biblionumber, $biblioitemnumber, '' ); };
349
            eval { ( $itemnumbers_ref, $errors_ref ) = AddItemBatchFromMarc( $record, $biblionumber, $biblioitemnumber, '' ); };
348
            if ( $@ ) {
350
            if ( $@ ) {
349
                warn "ERROR: Adding items to bib $biblionumber failed: $@\n";
351
                warn "ERROR: Adding items to bib $biblionumber failed: $@\n";
Lines 356-362 RECORD: while ( ) { Link Here
356
 			else{
358
 			else{
357
				printlog({id=>$id||$originalid||$biblionumber, op=>"insert",status=>"ok"}) if ($logfile);
359
				printlog({id=>$id||$originalid||$biblionumber, op=>"insert",status=>"ok"}) if ($logfile);
358
			}
360
			}
359
            if ($#{ $errors_ref } > -1) { 
361
            if ($dedup_barcode && grep { exists $_->{error_code} && $_->{error_code} eq 'duplicate_barcode' } @$errors_ref) {
362
                # Find the record called 'barcode'
363
                my ($tag, $sub) = C4::Biblio::GetMarcFromKohaField('items.barcode', '');
364
                # Now remove any items that didn't have a duplicate_barcode error,
365
                # erase the barcodes on items that did, and re-add those items.
366
                my %dupes;
367
                foreach my $i (0 .. $#{$errors_ref}) {
368
                    my $ref = $errors_ref->[$i];
369
                    if ($ref && $ref->{error_code} eq 'duplicate_barcode') {
370
                        $dupes{$ref->{item_sequence}} = 1;
371
                        # Delete the error message because we're going to
372
                        # retry this one.
373
                        delete $errors_ref->[$i];
374
                    }
375
                }
376
                my $seq = 0;
377
                foreach my $field ($record->field($tag)) {
378
                    $seq++;
379
                    if ($dupes{$seq}) {
380
                        # Here we remove the barcode
381
                        $field->delete_subfield(code => $sub);
382
                    } else {
383
                        # otherwise we delete the field because we don't want
384
                        # two of them
385
                        $record->delete_fields($field);
386
                    }
387
                }
388
                # Now re-add the record as before, adding errors to the prev list
389
                my $more_errors;
390
                eval { ( $itemnumbers_ref, $more_errors ) = AddItemBatchFromMarc( $record, $biblionumber, $biblioitemnumber, '' ); };
391
                if ( $@ ) {
392
                    warn "ERROR: Adding items to bib $biblionumber failed: $@\n";
393
                    printlog({id=>$id||$originalid||$biblionumber, op=>"insertitem",status=>"ERROR"}) if ($logfile);
394
                    # if we failed because of an exception, assume that
395
                    # the MARC columns in biblioitems were not set.
396
                    ModBiblioMarc( $record, $biblionumber, '' );
397
                    next RECORD;
398
                } else {
399
                    printlog({id=>$id||$originalid||$biblionumber, op=>"insert",status=>"ok"}) if ($logfile);
400
                }
401
                push @$errors_ref, @{ $more_errors };
402
            }
403
            if ($#{ $errors_ref } > -1) {
360
                report_item_errors($biblionumber, $errors_ref);
404
                report_item_errors($biblionumber, $errors_ref);
361
            }
405
            }
362
        }
406
        }
Lines 427-432 sub report_item_errors { Link Here
427
    my $errors_ref = shift;
471
    my $errors_ref = shift;
428
472
429
    foreach my $error (@{ $errors_ref }) {
473
    foreach my $error (@{ $errors_ref }) {
474
        next if !$error;
430
        my $msg = "Item not added (bib $biblionumber, item tag #$error->{'item_sequence'}, barcode $error->{'item_barcode'}): ";
475
        my $msg = "Item not added (bib $biblionumber, item tag #$error->{'item_sequence'}, barcode $error->{'item_barcode'}): ";
431
        my $error_code = $error->{'error_code'};
476
        my $error_code = $error->{'error_code'};
432
        $error_code =~ s/_/ /g;
477
        $error_code =~ s/_/ /g;
Lines 558-563 Store ids in 009 (usefull for authorities, where 001 contains the authid for Link Here
558
Koha, that can contain a very valuable info for authorities coming from LOC or
603
Koha, that can contain a very valuable info for authorities coming from LOC or
559
BNF. useless for biblios probably)
604
BNF. useless for biblios probably)
560
605
606
=item B<-dedupbarcodes>
607
608
If set, whenever a duplicate barcode is detected, it is removed and the attempt
609
to add the record is retried, thereby giving the record a blank barcode. This
610
is useful when something has set barcodes to be a biblio ID, or similar
611
(usually other software.)
612
561
=back
613
=back
562
614
563
=cut
615
=cut
564
- 

Return to bug 6199