|
Lines 45-50
use Koha::Logger;
Link Here
|
| 45 |
use Koha::Biblios; |
45 |
use Koha::Biblios; |
| 46 |
use Koha::SearchEngine; |
46 |
use Koha::SearchEngine; |
| 47 |
use Koha::SearchEngine::Search; |
47 |
use Koha::SearchEngine::Search; |
|
|
48 |
use Koha::Plugins::Handler; |
| 48 |
|
49 |
|
| 49 |
use open qw( :std :encoding(UTF-8) ); |
50 |
use open qw( :std :encoding(UTF-8) ); |
| 50 |
binmode(STDOUT, ":encoding(UTF-8)"); |
51 |
binmode(STDOUT, ":encoding(UTF-8)"); |
|
Lines 79-84
my $framework = '';
Link Here
|
| 79 |
my $localcust; |
80 |
my $localcust; |
| 80 |
my $marc_mod_template = ''; |
81 |
my $marc_mod_template = ''; |
| 81 |
my $marc_mod_template_id = -1; |
82 |
my $marc_mod_template_id = -1; |
|
|
83 |
my $to_marc_plugin; |
| 82 |
$| = 1; |
84 |
$| = 1; |
| 83 |
|
85 |
|
| 84 |
GetOptions( |
86 |
GetOptions( |
|
Lines 115-120
GetOptions(
Link Here
|
| 115 |
'framework=s' => \$framework, |
117 |
'framework=s' => \$framework, |
| 116 |
'custom:s' => \$localcust, |
118 |
'custom:s' => \$localcust, |
| 117 |
'marcmodtemplate:s' => \$marc_mod_template, |
119 |
'marcmodtemplate:s' => \$marc_mod_template, |
|
|
120 |
'tomarcplugin:s' => \$to_marc_plugin, |
| 118 |
); |
121 |
); |
| 119 |
|
122 |
|
| 120 |
$biblios ||= !$authorities; |
123 |
$biblios ||= !$authorities; |
|
Lines 254-279
my $searcher = Koha::SearchEngine::Search->new(
Link Here
|
| 254 |
print "Characteristic MARC flavour: $marc_flavour\n" if $verbose; |
257 |
print "Characteristic MARC flavour: $marc_flavour\n" if $verbose; |
| 255 |
my $starttime = gettimeofday; |
258 |
my $starttime = gettimeofday; |
| 256 |
|
259 |
|
| 257 |
my $fh = IO::File->new($input_marc_file); # don't let MARC::Batch open the file, as it applies the ':utf8' IO layer |
260 |
if ($to_marc_plugin) { |
| 258 |
if (defined $format && $format =~ /XML/i) { |
261 |
my $marc_records_blob = undef; |
| 259 |
# ugly hack follows -- MARC::File::XML, when used by MARC::Batch, |
262 |
{ |
| 260 |
# appears to try to convert incoming XML records from MARC-8 |
263 |
local $/ = undef; |
| 261 |
# to UTF-8. Setting the BinaryEncoding key turns that off |
264 |
open FILE, $input_marc_file; |
| 262 |
# TODO: see what happens to ISO-8859-1 XML files. |
265 |
binmode FILE, ':raw'; |
| 263 |
# TODO: determine if MARC::Batch can be fixed to handle |
266 |
$marc_records_blob = <FILE>; |
| 264 |
# XML records properly -- it probably should be |
267 |
close FILE; |
| 265 |
# be using a proper push or pull XML parser to |
268 |
} |
| 266 |
# extract the records, not using regexes to look |
269 |
$marc_records_blob = Koha::Plugins::Handler->run( |
| 267 |
# for <record>.*</record>. |
270 |
{ |
| 268 |
$MARC::File::XML::_load_args{BinaryEncoding} = 'utf-8'; |
271 |
class => $to_marc_plugin, |
| 269 |
my $recordformat = ($marc_flavour eq "MARC21" ? "USMARC" : uc($marc_flavour)); |
272 |
method => 'to_marc', |
| 270 |
#UNIMARC Authorities have a different way to manage encoding than UNIMARC biblios. |
273 |
params => { data => $marc_records_blob } |
| 271 |
$recordformat = $recordformat . "AUTH" if ($authorities and $marc_flavour ne "MARC21"); |
274 |
} |
| 272 |
$MARC::File::XML::_load_args{RecordFormat} = $recordformat; |
275 |
); |
| 273 |
$batch = MARC::Batch->new('XML', $fh); |
276 |
open(my $fh, '<', \$marc_records_blob); |
| 274 |
} |
277 |
binmode $fh, ':raw'; |
| 275 |
else { |
|
|
| 276 |
$batch = MARC::Batch->new('USMARC', $fh); |
278 |
$batch = MARC::Batch->new('USMARC', $fh); |
|
|
279 |
} else { |
| 280 |
my $fh = IO::File->new($input_marc_file); # don't let MARC::Batch open the file, as it applies the ':utf8' IO layer |
| 281 |
if (defined $format && $format =~ /XML/i) { |
| 282 |
# ugly hack follows -- MARC::File::XML, when used by MARC::Batch, |
| 283 |
# appears to try to convert incoming XML records from MARC-8 |
| 284 |
# to UTF-8. Setting the BinaryEncoding key turns that off |
| 285 |
# TODO: see what happens to ISO-8859-1 XML files. |
| 286 |
# TODO: determine if MARC::Batch can be fixed to handle |
| 287 |
# XML records properly -- it probably should be |
| 288 |
# be using a proper push or pull XML parser to |
| 289 |
# extract the records, not using regexes to look |
| 290 |
# for <record>.*</record>. |
| 291 |
$MARC::File::XML::_load_args{BinaryEncoding} = 'utf-8'; |
| 292 |
my $recordformat = ($marc_flavour eq "MARC21" ? "USMARC" : uc($marc_flavour)); |
| 293 |
#UNIMARC Authorities have a different way to manage encoding than UNIMARC biblios. |
| 294 |
$recordformat = $recordformat . "AUTH" if ($authorities and $marc_flavour ne "MARC21"); |
| 295 |
$MARC::File::XML::_load_args{RecordFormat} = $recordformat; |
| 296 |
$batch = MARC::Batch->new('XML', $fh); |
| 297 |
} |
| 298 |
else { |
| 299 |
$batch = MARC::Batch->new('USMARC', $fh); |
| 300 |
} |
| 277 |
} |
301 |
} |
| 278 |
|
302 |
|
| 279 |
$batch->warnings_off(); |
303 |
$batch->warnings_off(); |
|
Lines 962-967
modification template to apply as the MARC records are imported (these
Link Here
|
| 962 |
templates are created in the "MARC modification templates" tool in Koha). |
986 |
templates are created in the "MARC modification templates" tool in Koha). |
| 963 |
If not specified, no MARC modification templates are used (default). |
987 |
If not specified, no MARC modification templates are used (default). |
| 964 |
|
988 |
|
|
|
989 |
=item B<-tomarcplugin>=I<PLUGIN> |
| 990 |
|
| 991 |
Fully qualified class name of plugin with to_marc method for processing raw MARC data. |
| 992 |
|
| 965 |
=back |
993 |
=back |
| 966 |
|
994 |
|
| 967 |
=cut |
995 |
=cut |
| 968 |
- |
|
|