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

(-)a/C4/ImportBatch.pm (-7 / +37 lines)
Lines 399-411 sub BatchStageMarcRecords { Link Here
399
        SetImportBatchItemAction($batch_id, 'ignore');
399
        SetImportBatchItemAction($batch_id, 'ignore');
400
    }
400
    }
401
401
402
    $marc_records = Koha::Plugins::Handler->run(
403
        {
404
            class  => $to_marc_plugin,
405
            method => 'to_marc',
406
            params => { data => $marc_records }
407
        }
408
    ) if $to_marc_plugin && @$marc_records;
409
402
410
    my $marc_type = C4::Context->preference('marcflavour');
403
    my $marc_type = C4::Context->preference('marcflavour');
411
    $marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth');
404
    $marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth');
Lines 1556-1561 sub RecordsFromMARCXMLFile { Link Here
1556
    return (\@errors, \@marcRecords);
1549
    return (\@errors, \@marcRecords);
1557
}
1550
}
1558
1551
1552
=head2 RecordsFromMarcPlugin
1553
1554
    Converts text of input_file into array of MARC records with to_marc plugin
1555
1556
=cut
1557
1558
sub RecordsFromMarcPlugin {
1559
    my ($input_file, $plugin, $encoding) = @_;
1560
1561
    # Read input file
1562
    open IN, "<$input_file" or die "$0: cannot open input file $input_file: $!\n";
1563
    my ( $text, $marc, @return );
1564
    $/ = "\035";
1565
    while (<IN>) {
1566
        s/^\s+//;
1567
        s/\s+$//;
1568
        next unless $_;
1569
        $text .= $_;
1570
    }
1571
    close IN;
1572
1573
    # Convert to large MARC blob with plugin
1574
    $text = Koha::Plugins::Handler->run({
1575
        class  => $plugin,
1576
        method => 'to_marc',
1577
        params => { data => $text },
1578
    });
1579
1580
    # Convert to array of MARC records
1581
    my $marc_type = C4::Context->preference('marcflavour');
1582
    foreach my $blob ( split(/\x1D/, $text) ) {
1583
        my ($marcrecord) = MarcToUTF8Record($blob, $marc_type, $encoding);
1584
        push @return, $marcrecord;
1585
    }
1586
    return \@return;
1587
}
1588
1559
# internal functions
1589
# internal functions
1560
1590
1561
sub _create_import_record {
1591
sub _create_import_record {
(-)a/tools/stage-marc-import.pl (-2 / +3 lines)
Lines 92-99 if ($completedJobID) { Link Here
92
    my ( $errors, $marcrecords );
92
    my ( $errors, $marcrecords );
93
    if( $format eq 'MARCXML' ) {
93
    if( $format eq 'MARCXML' ) {
94
        ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromMARCXMLFile( $file, $encoding);
94
        ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromMARCXMLFile( $file, $encoding);
95
    } else {
95
    } elsif( $format eq 'MARC' ) {
96
        ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromISO2709File( $file, $record_type, $encoding );
96
        ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromISO2709File( $file, $record_type, $encoding );
97
    } else { # plugin
98
        ( $marcrecords ) = C4::ImportBatch::RecordsFromMarcPlugin( $file, $to_marc_plugin, $encoding );
97
    }
99
    }
98
    warn "$filename: " . ( join ',', @$errors ) if @$errors;
100
    warn "$filename: " . ( join ',', @$errors ) if @$errors;
99
        # no need to exit if we have no records (or only errors) here
101
        # no need to exit if we have no records (or only errors) here
100
- 

Return to bug 19049