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

(-)a/C4/ImportBatch.pm (-2 / +26 lines)
Lines 1505-1517 sub RecordsFromISO2709File { Link Here
1505
1505
1506
    open IN, "<$input_file" or die "$0: cannot open input file $input_file: $!\n";
1506
    open IN, "<$input_file" or die "$0: cannot open input file $input_file: $!\n";
1507
    my @marc_records;
1507
    my @marc_records;
1508
    my $count = 0;
1508
    $/ = "\035";
1509
    $/ = "\035";
1509
    while (<IN>) {
1510
    while (<IN>) {
1510
        s/^\s+//;
1511
        s/^\s+//;
1511
        s/\s+$//;
1512
        s/\s+$//;
1512
        next unless $_; # skip if record has only whitespace, as might occur
1513
        next unless $_; # skip if record has only whitespace, as might occur
1513
                        # if file includes newlines between each MARC record
1514
                        # if file includes newlines between each MARC record
1515
        ++$count;
1514
        my ($marc_record, $charset_guessed, $char_errors) = MarcToUTF8Record($_, $marc_type, $encoding);
1516
        my ($marc_record, $charset_guessed, $char_errors) = MarcToUTF8Record($_, $marc_type, $encoding);
1517
        # Ignore holdings records
1518
        if ($record_type eq 'biblio' && $marc_type eq 'MARC21') {
1519
            my $leader = $marc_record->leader();
1520
            if ($leader =~ /^.{6}[uvxy]/) {
1521
                push @errors, "Ignoring record $count (holdings record)";
1522
                next;
1523
            }
1524
        }
1525
1515
        push @marc_records, $marc_record;
1526
        push @marc_records, $marc_record;
1516
        if ($charset_guessed ne $encoding) {
1527
        if ($charset_guessed ne $encoding) {
1517
            push @errors,
1528
            push @errors,
Lines 1536-1550 Returns two array refs. Link Here
1536
=cut
1547
=cut
1537
1548
1538
sub RecordsFromMARCXMLFile {
1549
sub RecordsFromMARCXMLFile {
1539
    my ( $filename, $encoding ) = @_;
1550
    my ( $filename, $record_type, $encoding ) = @_;
1551
1552
    my $marcflavour = C4::Context->preference('marcflavour');
1540
    my $batch = MARC::File::XML->in( $filename );
1553
    my $batch = MARC::File::XML->in( $filename );
1541
    my ( @marcRecords, @errors, $record );
1554
    my ( @marcRecords, @errors, $record );
1555
    my $count = 0;
1542
    do {
1556
    do {
1557
        ++$count;
1543
        eval { $record = $batch->next( $encoding ); };
1558
        eval { $record = $batch->next( $encoding ); };
1544
        if ($@) {
1559
        if ($@) {
1545
            push @errors, $@;
1560
            push @errors, $@;
1546
        }
1561
        }
1547
        push @marcRecords, $record if $record;
1562
        # Ignore holdings records
1563
        my $valid = 1;
1564
        if ($record && $record_type eq 'biblio' && $marcflavour eq 'MARC21') {
1565
            my $leader = $record->leader();
1566
            if ($leader =~ /^.{6}[uvxy]/) {
1567
                push @errors, "Ignoring record $count (holdings record)";
1568
                $valid = 0;
1569
            }
1570
        }
1571
        push @marcRecords, $record if $record && $valid;
1548
    } while( $record );
1572
    } while( $record );
1549
    return (\@errors, \@marcRecords);
1573
    return (\@errors, \@marcRecords);
1550
}
1574
}
(-)a/tools/stage-marc-import.pl (-2 / +1 lines)
Lines 93-99 if ($completedJobID) { Link Here
93
93
94
    my ( $errors, $marcrecords );
94
    my ( $errors, $marcrecords );
95
    if( $format eq 'MARCXML' ) {
95
    if( $format eq 'MARCXML' ) {
96
        ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromMARCXMLFile( $file, $encoding);
96
        ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromMARCXMLFile( $file, $record_type, $encoding);
97
    } elsif( $format eq 'ISO2709' ) {
97
    } elsif( $format eq 'ISO2709' ) {
98
        ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromISO2709File( $file, $record_type, $encoding );
98
        ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromISO2709File( $file, $record_type, $encoding );
99
    } else { # plugin based
99
    } else { # plugin based
100
- 

Return to bug 20447