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

(-)a/misc/migration_tools/bulkmarcimport.pl (-19 / +28 lines)
Lines 46-52 use Koha::SearchEngine::Search; Link Here
46
46
47
use open qw( :std :encoding(UTF-8) );
47
use open qw( :std :encoding(UTF-8) );
48
binmode( STDOUT, ":encoding(UTF-8)" );
48
binmode( STDOUT, ":encoding(UTF-8)" );
49
my ( $input_marc_file, $number, $offset, $cleanisbn ) = ( '', 0, 0, 1 );
49
my ( $input_marc_file, $offset, $cleanisbn ) = ( '', 0, 1 );
50
my $number;
50
my $version;
51
my $version;
51
my $delete;
52
my $delete;
52
my $test_parameter;
53
my $test_parameter;
Lines 298-304 my $yamlhash; Link Here
298
# Skip file offset
299
# Skip file offset
299
if ($offset) {
300
if ($offset) {
300
    print "Skipping file offset: $offset records\n";
301
    print "Skipping file offset: $offset records\n";
301
    $batch->next() while ( $offset-- );
302
    eval { $batch->next() } while ( $offset-- );
302
}
303
}
303
304
304
my ( $tagid, $subfieldid );
305
my ( $tagid, $subfieldid );
Lines 333-354 RECORD: while () { Link Here
333
334
334
    my $record;
335
    my $record;
335
336
336
    # get record
337
    # max number (n) is defined and reached
337
    eval { $record = $batch->next() };
338
    $records_exhausted = 1 if defined($number) && $record_number >= $number;
338
    if ($@) {
339
339
        print "Bad MARC record $record_number: $@ skipped\n";
340
    if ( !$records_exhausted ) {
340
341
341
        # FIXME - because MARC::Batch->next() combines grabbing the next
342
        # get record
342
        # blob and parsing it into one operation, a correctable condition
343
        eval { $record = $batch->next() };
343
        # such as a MARC-8 record claiming that it's UTF-8 can't be recovered
344
        if ($@) {
344
        # from because we don't have access to the original blob.  Note
345
345
        # that the staging import can deal with this condition (via
346
            # do increase number for broken records
346
        # C4::Charset::MarcToUTF8Record) because it doesn't use MARC::Batch.
347
            $record_number++;
347
        next;
348
            print "Bad MARC record $record_number: $@ skipped\n";
349
350
            # FIXME - because MARC::Batch->next() combines grabbing the next
351
            # blob and parsing it into one operation, a correctable condition
352
            # such as a MARC-8 record claiming that it's UTF-8 can't be recovered
353
            # from because we don't have access to the original blob.  Note
354
            # that the staging import can deal with this condition (via
355
            # C4::Charset::MarcToUTF8Record) because it doesn't use MARC::Batch.
356
            next;
357
        }
348
    }
358
    }
349
    if ($record) {
350
        $record_number++;
351
359
360
    if ( $record && !$records_exhausted ) {
361
        $record_number++;
352
        if ($skip_bad_records) {
362
        if ($skip_bad_records) {
353
            my $xml = $record->as_xml_record();
363
            my $xml = $record->as_xml_record();
354
            eval { MARC::Record::new_from_xml( $xml, 'UTF-8', "MARC21" ); };
364
            eval { MARC::Record::new_from_xml( $xml, 'UTF-8', "MARC21" ); };
Lines 721-727 RECORD: while () { Link Here
721
        $records_exhausted = 1;
731
        $records_exhausted = 1;
722
    }
732
    }
723
733
724
    if ( !$test_parameter && $record_number % $commitnum == 0 || $record_number == $number || $records_exhausted ) {
734
    if ( !$test_parameter && $record_number % $commitnum == 0 || $records_exhausted ) {
725
        if ($indexer) {
735
        if ($indexer) {
726
            $indexer->update_index( \@search_engine_record_ids, \@search_engine_records ) unless $skip_indexing;
736
            $indexer->update_index( \@search_engine_record_ids, \@search_engine_records ) unless $skip_indexing;
727
            if ( C4::Context->preference('AutoLinkBiblios') ) {
737
            if ( C4::Context->preference('AutoLinkBiblios') ) {
Lines 735-741 RECORD: while () { Link Here
735
        $schema->txn_commit;
745
        $schema->txn_commit;
736
        $schema->txn_begin;
746
        $schema->txn_begin;
737
    }
747
    }
738
    last if $record_number == $number || $records_exhausted;
748
    last if $records_exhausted;
739
}
749
}
740
750
741
if ( !$test_parameter ) {
751
if ( !$test_parameter ) {
742
- 

Return to bug 41681