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

(-)a/misc/migration_tools/bulkmarcimport.pl (-24 / +52 lines)
Lines 42-47 use Koha::Logger; Link Here
42
use Koha::Biblios;
42
use Koha::Biblios;
43
use Koha::SearchEngine;
43
use Koha::SearchEngine;
44
use Koha::SearchEngine::Search;
44
use Koha::SearchEngine::Search;
45
use Koha::Plugins::Handler;
45
46
46
use open qw( :std :encoding(UTF-8) );
47
use open qw( :std :encoding(UTF-8) );
47
binmode( STDOUT, ":encoding(UTF-8)" );
48
binmode( STDOUT, ":encoding(UTF-8)" );
Lines 76-82 my $framework = ''; Link Here
76
my $localcust;
77
my $localcust;
77
my $marc_mod_template    = '';
78
my $marc_mod_template    = '';
78
my $marc_mod_template_id = -1;
79
my $marc_mod_template_id = -1;
79
my $skip_indexing        = 0;
80
+my $to_marc_plugin;
81
my $skip_indexing = 0;
80
my $skip_bad_records;
82
my $skip_bad_records;
81
$| = 1;
83
$| = 1;
82
84
Lines 114-119 GetOptions( Link Here
114
    'framework=s'         => \$framework,
116
    'framework=s'         => \$framework,
115
    'custom:s'            => \$localcust,
117
    'custom:s'            => \$localcust,
116
    'marcmodtemplate:s'   => \$marc_mod_template,
118
    'marcmodtemplate:s'   => \$marc_mod_template,
119
    'tomarcplugin:s'      => \$to_marc_plugin,
117
    'si|skip_indexing'    => \$skip_indexing,
120
    'si|skip_indexing'    => \$skip_indexing,
118
    'sk|skip_bad_records' => \$skip_bad_records,
121
    'sk|skip_bad_records' => \$skip_bad_records,
119
);
122
);
Lines 262-290 my $searcher = Koha::SearchEngine::Search->new( Link Here
262
print "Characteristic MARC flavour: $marc_flavour\n" if $verbose;
265
print "Characteristic MARC flavour: $marc_flavour\n" if $verbose;
263
my $starttime = gettimeofday;
266
my $starttime = gettimeofday;
264
267
265
# don't let MARC::Batch open the file, as it applies the ':utf8' IO layer
268
if ($to_marc_plugin) {
266
my $fh = IO::File->new($input_marc_file) or die "Could not open $input_marc_file: $!";
269
    my $marc_records_blob = undef;
267
270
    {
268
if ( defined $format && $format =~ /XML/i ) {
271
        local $/ = undef;
269
272
        open( my $fh, $input_marc_file, '<' );
270
    # ugly hack follows -- MARC::File::XML, when used by MARC::Batch,
273
        binmode $fh, ':raw';
271
    # appears to try to convert incoming XML records from MARC-8
274
        $marc_records_blob = <$fh>;
272
    # to UTF-8.  Setting the BinaryEncoding key turns that off
275
        close($fh);
273
    # TODO: see what happens to ISO-8859-1 XML files.
276
    }
274
    # TODO: determine if MARC::Batch can be fixed to handle
277
    $marc_records_blob = Koha::Plugins::Handler->run(
275
    #       XML records properly -- it probably should be
278
        {
276
    #       be using a proper push or pull XML parser to
279
            class  => $to_marc_plugin,
277
    #       extract the records, not using regexes to look
280
            method => 'to_marc',
278
    #       for <record>.*</record>.
281
            params => { data => $marc_records_blob }
279
    $MARC::File::XML::_load_args{BinaryEncoding} = 'utf-8';
282
        }
280
    my $recordformat = ( $marc_flavour eq "MARC21" ? "USMARC" : uc($marc_flavour) );
283
    );
281
284
    open( my $fh, '<', \$marc_records_blob );
282
    #UNIMARC Authorities have a different way to manage encoding than UNIMARC biblios.
285
    binmode $fh, ':raw';
283
    $recordformat = $recordformat . "AUTH" if ( $authorities and $marc_flavour ne "MARC21" );
284
    $MARC::File::XML::_load_args{RecordFormat} = $recordformat;
285
    $batch = MARC::Batch->new( 'XML', $fh );
286
} else {
287
    $batch = MARC::Batch->new( 'USMARC', $fh );
286
    $batch = MARC::Batch->new( 'USMARC', $fh );
287
} else {
288
289
    # don't let MARC::Batch open the file, as it applies the ':utf8' IO layer
290
    my $fh = IO::File->new($input_marc_file) or die "Could not open $input_marc_file: $!";
291
292
    if ( defined $format && $format =~ /XML/i ) {
293
294
        # ugly hack follows -- MARC::File::XML, when used by MARC::Batch,
295
        # appears to try to convert incoming XML records from MARC-8
296
        # to UTF-8.  Setting the BinaryEncoding key turns that off
297
        # TODO: see what happens to ISO-8859-1 XML files.
298
        # TODO: determine if MARC::Batch can be fixed to handle
299
        #       XML records properly -- it probably should be
300
        #       be using a proper push or pull XML parser to
301
        #       extract the records, not using regexes to look
302
        #       for <record>.*</record>.
303
        $MARC::File::XML::_load_args{BinaryEncoding} = 'utf-8';
304
        my $recordformat = ( $marc_flavour eq "MARC21" ? "USMARC" : uc($marc_flavour) );
305
306
        #UNIMARC Authorities have a different way to manage encoding than UNIMARC biblios.
307
        $recordformat = $recordformat . "AUTH" if ( $authorities and $marc_flavour ne "MARC21" );
308
        $MARC::File::XML::_load_args{RecordFormat} = $recordformat;
309
        $batch = MARC::Batch->new( 'XML', $fh );
310
    } else {
311
        $batch = MARC::Batch->new( 'USMARC', $fh );
312
    }
288
}
313
}
289
314
290
$batch->warnings_off();
315
$batch->warnings_off();
Lines 1061-1066 If set, check the validity of records before adding. If they are invalid we will Link Here
1061
print the output of MARC::Lint->check_record and skip them during the import. Without
1086
print the output of MARC::Lint->check_record and skip them during the import. Without
1062
this option bad records may kill the job.
1087
this option bad records may kill the job.
1063
1088
1089
=item B<-tomarcplugin>=I<PLUGIN>
1090
1091
Fully qualified class name of plugin with to_marc method for processing raw MARC data.
1092
1064
=back
1093
=back
1065
1094
1066
=cut
1095
=cut
1067
- 

Return to bug 29597