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-81
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; |
|
|
80 |
+my $to_marc_plugin; |
79 |
my $skip_indexing = 0; |
81 |
my $skip_indexing = 0; |
80 |
my $skip_bad_records; |
82 |
my $skip_bad_records; |
81 |
$| = 1; |
83 |
$| = 1; |
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 |
|
266 |
my $fh = IO::File->new($input_marc_file) or die "Could not open $input_marc_file: $!"; |
269 |
if ($to_marc_plugin) { |
267 |
|
270 |
my $marc_records_blob = undef; |
268 |
if ( defined $format && $format =~ /XML/i ) { |
271 |
{ |
269 |
|
272 |
local $/ = undef; |
270 |
# ugly hack follows -- MARC::File::XML, when used by MARC::Batch, |
273 |
open FILE, $input_marc_file; |
271 |
# appears to try to convert incoming XML records from MARC-8 |
274 |
binmode FILE, ':raw'; |
272 |
# to UTF-8. Setting the BinaryEncoding key turns that off |
275 |
$marc_records_blob = <FILE>; |
273 |
# TODO: see what happens to ISO-8859-1 XML files. |
276 |
close FILE; |
274 |
# TODO: determine if MARC::Batch can be fixed to handle |
277 |
} |
275 |
# XML records properly -- it probably should be |
278 |
$marc_records_blob = Koha::Plugins::Handler->run( |
276 |
# be using a proper push or pull XML parser to |
279 |
{ |
277 |
# extract the records, not using regexes to look |
280 |
class => $to_marc_plugin, |
278 |
# for <record>.*</record>. |
281 |
method => 'to_marc', |
279 |
$MARC::File::XML::_load_args{BinaryEncoding} = 'utf-8'; |
282 |
params => { data => $marc_records_blob } |
280 |
my $recordformat = ( $marc_flavour eq "MARC21" ? "USMARC" : uc($marc_flavour) ); |
283 |
} |
281 |
|
284 |
); |
282 |
#UNIMARC Authorities have a different way to manage encoding than UNIMARC biblios. |
285 |
open(my $fh, '<', \$marc_records_blob); |
283 |
$recordformat = $recordformat . "AUTH" if ( $authorities and $marc_flavour ne "MARC21" ); |
286 |
binmode $fh, ':raw'; |
284 |
$MARC::File::XML::_load_args{RecordFormat} = $recordformat; |
287 |
$batch = MARC::Batch->new('USMARC', $fh); |
285 |
$batch = MARC::Batch->new( 'XML', $fh ); |
|
|
286 |
} else { |
288 |
} else { |
287 |
$batch = MARC::Batch->new( 'USMARC', $fh ); |
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 1052-1057
If set, check the validity of records before adding. If they are invalid we will
Link Here
|
1052 |
print the output of MARC::Lint->check_record and skip them during the import. Without |
1077 |
print the output of MARC::Lint->check_record and skip them during the import. Without |
1053 |
this option bad records may kill the job. |
1078 |
this option bad records may kill the job. |
1054 |
|
1079 |
|
|
|
1080 |
=item B<-tomarcplugin>=I<PLUGIN> |
1081 |
|
1082 |
Fully qualified class name of plugin with to_marc method for processing raw MARC data. |
1083 |
|
1055 |
=back |
1084 |
=back |
1056 |
|
1085 |
|
1057 |
=cut |
1086 |
=cut |
1058 |
- |
|
|