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

(-)a/C4/Items.pm (-1 / +4 lines)
Lines 303-309 Sequence number of original item tag in the MARC record. Link Here
303
Item barcode, provide to assist in the construction of
303
Item barcode, provide to assist in the construction of
304
useful error messages.
304
useful error messages.
305
305
306
=item error_condition
306
=item error_code
307
307
308
Code representing the error condition.  Can be 'duplicate_barcode',
308
Code representing the error condition.  Can be 'duplicate_barcode',
309
'invalid_homebranch', or 'invalid_holdingbranch'.
309
'invalid_homebranch', or 'invalid_holdingbranch'.
Lines 323-328 sub AddItemBatchFromMarc { Link Here
323
    my @errors = ();
323
    my @errors = ();
324
    my $dbh = C4::Context->dbh;
324
    my $dbh = C4::Context->dbh;
325
325
326
    # We modify the record, so lets work on a clone so we don't change the
327
    # original.
328
    $record = $record->clone();
326
    # loop through the item tags and start creating items
329
    # loop through the item tags and start creating items
327
    my @bad_item_fields = ();
330
    my @bad_item_fields = ();
328
    my ($itemtag, $itemsubfield) = &GetMarcFromKohaField("items.itemnumber",'');
331
    my ($itemtag, $itemsubfield) = &GetMarcFromKohaField("items.itemnumber",'');
(-)a/misc/migration_tools/bulkmarcimport.pl (-3 / +54 lines)
Lines 33-40 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);
37
my $cleanisbn = 1;
36
my $cleanisbn = 1;
37
my ($sourcetag,$sourcesubfield,$idmapfl, $dedup_barcode);
38
38
39
$|=1;
39
$|=1;
40
40
Lines 61-66 GetOptions( Link Here
61
    'y:s' => \$sourcesubfield,
61
    'y:s' => \$sourcesubfield,
62
    'idmap:s' => \$idmapfl,
62
    'idmap:s' => \$idmapfl,
63
    'cleanisbn!'     => \$cleanisbn,
63
    'cleanisbn!'     => \$cleanisbn,
64
    'dedupbarcode' => \$dedup_barcode,
64
);
65
);
65
$biblios=!$authorities||$biblios;
66
$biblios=!$authorities||$biblios;
66
67
Lines 317-322 RECORD: while ( ) { Link Here
317
 			else{
318
 			else{
318
				printlog({id=>$id||$originalid||$biblionumber, op=>"insert",status=>"ok"}) if ($logfile);
319
				printlog({id=>$id||$originalid||$biblionumber, op=>"insert",status=>"ok"}) if ($logfile);
319
			}
320
			}
321
			my $clone_record = $record->clone();
320
            eval { ( $itemnumbers_ref, $errors_ref ) = AddItemBatchFromMarc( $record, $biblionumber, $biblioitemnumber, '' ); };
322
            eval { ( $itemnumbers_ref, $errors_ref ) = AddItemBatchFromMarc( $record, $biblionumber, $biblioitemnumber, '' ); };
321
            if ( $@ ) {
323
            if ( $@ ) {
322
                warn "ERROR: Adding items to bib $biblionumber failed: $@\n";
324
                warn "ERROR: Adding items to bib $biblionumber failed: $@\n";
Lines 329-335 RECORD: while ( ) { Link Here
329
 			else{
331
 			else{
330
				printlog({id=>$id||$originalid||$biblionumber, op=>"insert",status=>"ok"}) if ($logfile);
332
				printlog({id=>$id||$originalid||$biblionumber, op=>"insert",status=>"ok"}) if ($logfile);
331
			}
333
			}
332
            if ($#{ $errors_ref } > -1) { 
334
            if ($dedup_barcode && grep { exists $_->{error_code} && $_->{error_code} eq 'duplicate_barcode' } @$errors_ref) {
335
                # Find the record called 'barcode'
336
                my ($tag, $sub) = C4::Biblio::GetMarcFromKohaField('items.barcode', '');
337
                # Now remove any items that didn't have a duplicate_barcode error,
338
                # erase the barcodes on items that did, and re-add those items.
339
                my %dupes;
340
                foreach my $i (0 .. $#{$errors_ref}) {
341
                    my $ref = $errors_ref->[$i];
342
                    if ($ref && $ref->{error_code} eq 'duplicate_barcode') {
343
                        $dupes{$ref->{item_sequence}} = 1;
344
                        # Delete the error message because we're going to
345
                        # retry this one.
346
                        delete $errors_ref->[$i];
347
                    }
348
                }
349
                my $seq = 0;
350
                foreach my $field ($record->field($tag)) {
351
                    $seq++;
352
                    if ($dupes{$seq}) {
353
                        # Here we remove the barcode
354
                        $field->delete_subfield(code => $sub);
355
                    } else {
356
                        # otherwise we delete the field because we don't want
357
                        # two of them
358
                        $record->delete_fields($field);
359
                    }
360
                }
361
                # Now re-add the record as before, adding errors to the prev list
362
                my $more_errors;
363
                eval { ( $itemnumbers_ref, $more_errors ) = AddItemBatchFromMarc( $record, $biblionumber, $biblioitemnumber, '' ); };
364
                if ( $@ ) {
365
                    warn "ERROR: Adding items to bib $biblionumber failed: $@\n";
366
                    printlog({id=>$id||$originalid||$biblionumber, op=>"insertitem",status=>"ERROR"}) if ($logfile);
367
                    # if we failed because of an exception, assume that
368
                    # the MARC columns in biblioitems were not set.
369
                    ModBiblioMarc( $record, $biblionumber, '' );
370
                    next RECORD;
371
                } else {
372
                    printlog({id=>$id||$originalid||$biblionumber, op=>"insert",status=>"ok"}) if ($logfile);
373
                }
374
                push @$errors_ref, @{ $more_errors };
375
            }
376
            if ($#{ $errors_ref } > -1) {
333
                report_item_errors($biblionumber, $errors_ref);
377
                report_item_errors($biblionumber, $errors_ref);
334
            }
378
            }
335
        }
379
        }
Lines 400-405 sub report_item_errors { Link Here
400
    my $errors_ref = shift;
444
    my $errors_ref = shift;
401
445
402
    foreach my $error (@{ $errors_ref }) {
446
    foreach my $error (@{ $errors_ref }) {
447
        next if !$error;
403
        my $msg = "Item not added (bib $biblionumber, item tag #$error->{'item_sequence'}, barcode $error->{'item_barcode'}): ";
448
        my $msg = "Item not added (bib $biblionumber, item tag #$error->{'item_sequence'}, barcode $error->{'item_barcode'}): ";
404
        my $error_code = $error->{'error_code'};
449
        my $error_code = $error->{'error_code'};
405
        $error_code =~ s/_/ /g;
450
        $error_code =~ s/_/ /g;
Lines 536-541 Store ids in 009 (usefull for authorities, where 001 contains the authid for Link Here
536
Koha, that can contain a very valuable info for authorities coming from LOC or
581
Koha, that can contain a very valuable info for authorities coming from LOC or
537
BNF. useless for biblios probably)
582
BNF. useless for biblios probably)
538
583
584
=item B<-dedupbarcodes>
585
586
If set, whenever a duplicate barcode is detected, it is removed and the attempt
587
to add the record is retried, thereby giving the record a blank barcode. This
588
is useful when something has set barcodes to be a biblio ID, or similar
589
(usually other software.)
590
539
=back
591
=back
540
592
541
=cut
593
=cut
542
- 

Return to bug 6199