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

(-)a/C4/ImportBatch.pm (-12 / +12 lines)
Lines 1473-1483 Reads ISO2709 binary porridge from the given file and creates MARC::Record-objec Link Here
1473
@PARAM2, String, see stage_file.pl
1473
@PARAM2, String, see stage_file.pl
1474
@PARAM3, String, should be utf8
1474
@PARAM3, String, should be utf8
1475
1475
1476
Returns two array refs.
1477
1476
=cut
1478
=cut
1477
1479
1478
sub RecordsFromISO2709File {
1480
sub RecordsFromISO2709File {
1479
    my ($input_file, $record_type, $encoding) = @_;
1481
    my ($input_file, $record_type, $encoding) = @_;
1480
    my $errors;
1482
    my @errors;
1481
1483
1482
    my $marc_type = C4::Context->preference('marcflavour');
1484
    my $marc_type = C4::Context->preference('marcflavour');
1483
    $marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth');
1485
    $marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth');
Lines 1493-1532 sub RecordsFromISO2709File { Link Here
1493
        my ($marc_record, $charset_guessed, $char_errors) = MarcToUTF8Record($_, $marc_type, $encoding);
1495
        my ($marc_record, $charset_guessed, $char_errors) = MarcToUTF8Record($_, $marc_type, $encoding);
1494
        push @marc_records, $marc_record;
1496
        push @marc_records, $marc_record;
1495
        if ($charset_guessed ne $encoding) {
1497
        if ($charset_guessed ne $encoding) {
1496
            $errors = '' unless $errors;
1498
            push @errors,
1497
            $errors .= "Unexpected charset $charset_guessed, expecting $encoding\n";
1499
                "Unexpected charset $charset_guessed, expecting $encoding\n";
1498
        }
1500
        }
1499
    }
1501
    }
1500
    close IN;
1502
    close IN;
1501
    return ($errors, \@marc_records);
1503
    return ( \@errors, \@marc_records );
1502
}
1504
}
1503
1505
1504
=head RecordsFromMARCXMLFile
1506
=head RecordsFromMARCXMLFile
1505
1507
1506
    my ($errors, $records) = C4::ImportBatch::RecordsFromMARCXMLFile($input_file, $encoding);
1508
    my ($errors, $records) = C4::ImportBatch::RecordsFromMARCXMLFile($input_file, $encoding);
1507
1509
1508
1509
1510
Creates MARC::Record-objects out of the given MARCXML-file.
1510
Creates MARC::Record-objects out of the given MARCXML-file.
1511
1511
1512
@PARAM1, String, absolute path to the ISO2709 file.
1512
@PARAM1, String, absolute path to the ISO2709 file.
1513
@PARAM2, String, should be utf8
1513
@PARAM2, String, should be utf8
1514
1514
1515
Returns two array refs.
1516
1515
=cut
1517
=cut
1516
1518
1517
sub RecordsFromMARCXMLFile {
1519
sub RecordsFromMARCXMLFile {
1518
    my ( $filename, $encoding ) = @_;
1520
    my ( $filename, $encoding ) = @_;
1519
    my $batch = MARC::File::XML->in( $filename );
1521
    my $batch = MARC::File::XML->in( $filename );
1520
    my @marcRecords;
1522
    my ( @marcRecords, @errors, $record );
1521
    my @errors;
1522
    do {
1523
    do {
1523
        eval {
1524
        eval { $record = $batch->next( $encoding ); };
1524
            my $record = $batch->next($encoding);
1525
            push @marcRecords, $record if $record;
1526
        };
1527
        if ($@) {
1525
        if ($@) {
1528
            push @errors, $@;
1526
            push @errors, $@;
1527
            last;
1529
        }
1528
        }
1529
        push @marcRecords, $record if $record;
1530
    } while( $record );
1530
    } while( $record );
1531
    return (\@errors, \@marcRecords);
1531
    return (\@errors, \@marcRecords);
1532
}
1532
}
(-)a/misc/stage_file.pl (-2 / +2 lines)
Lines 94-101 sub process_batch { Link Here
94
    my ($format, $input_file, $record_type, $match, $add_items, $batch_comment) = @_;
94
    my ($format, $input_file, $record_type, $match, $add_items, $batch_comment) = @_;
95
95
96
    my ($errors, $marc_records) = C4::ImportBatch::RecordsFromISO2709File($input_file, $record_type, $encoding) if $format eq 'ISO2709';
96
    my ($errors, $marc_records) = C4::ImportBatch::RecordsFromISO2709File($input_file, $record_type, $encoding) if $format eq 'ISO2709';
97
    warn $errors if $errors;
97
    warn "@$errors\n" if @$errors;
98
    $marc_records = C4::ImportBatch::RecordsFromMARCXMLFile($input_file, $encoding) if $format eq 'MARCXML';
98
    ( $errors, $marc_records ) = C4::ImportBatch::RecordsFromMARCXMLFile($input_file, $encoding) if $format eq 'MARCXML';
99
    my $num_input_records = ($marc_records) ? scalar(@$marc_records) : 0;
99
    my $num_input_records = ($marc_records) ? scalar(@$marc_records) : 0;
100
100
101
    print "... staging MARC records -- please wait\n";
101
    print "... staging MARC records -- please wait\n";
(-)a/tools/stage-marc-import.pl (-3 / +6 lines)
Lines 87-94 if ($completedJobID) { Link Here
87
} elsif ($fileID) {
87
} elsif ($fileID) {
88
    my $upload = Koha::Upload->new->get({ id => $fileID });
88
    my $upload = Koha::Upload->new->get({ id => $fileID });
89
    my $filename = $upload->{path};
89
    my $filename = $upload->{path};
90
	my $marcrecord='';
90
    my ( $errors, $marcrecords );
91
    my ($errors, $marcrecords) = C4::ImportBatch::RecordsFromISO2709File($uploaded_file->filename(), $record_type, $encoding);
91
    if( $filename =~ /\.[^.]*xml$/i ) { # like .xml or .marcxml
92
        ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromMARCXMLFile( $filename, $encoding);
93
    } else {
94
        ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromISO2709File( $filename, $record_type, $encoding );
95
    }
92
96
93
    my $job = undef;
97
    my $job = undef;
94
    my $dbh;
98
    my $dbh;
95
- 

Return to bug 10407