Lines 326-340
sub ModAuthInBatch {
Link Here
|
326 |
=cut |
326 |
=cut |
327 |
|
327 |
|
328 |
sub BatchStageMarcRecords { |
328 |
sub BatchStageMarcRecords { |
329 |
my $record_type = shift; |
329 |
my ($record_type, $encoding, $marc_records, $file_name, |
330 |
my $encoding = shift; |
330 |
$marc_modification_template, $comments, $branch_code, $parse_items, |
331 |
my $marc_records = shift; |
331 |
$leave_as_staging) = @_; |
332 |
my $file_name = shift; |
|
|
333 |
my $marc_modification_template = shift; |
334 |
my $comments = shift; |
335 |
my $branch_code = shift; |
336 |
my $parse_items = shift; |
337 |
my $leave_as_staging = shift; |
338 |
|
332 |
|
339 |
# optional callback to monitor status |
333 |
# optional callback to monitor status |
340 |
# of job |
334 |
# of job |
Lines 368-391
sub BatchStageMarcRecords {
Link Here
|
368 |
my $num_items = 0; |
362 |
my $num_items = 0; |
369 |
# FIXME - for now, we're dealing only with bibs |
363 |
# FIXME - for now, we're dealing only with bibs |
370 |
my $rec_num = 0; |
364 |
my $rec_num = 0; |
371 |
foreach my $marc_blob (split(/\x1D/, $marc_records)) { |
365 |
|
372 |
$marc_blob =~ s/^\s+//g; |
366 |
foreach my $marc_record (@$marc_records) { |
373 |
$marc_blob =~ s/\s+$//g; |
|
|
374 |
next unless $marc_blob; |
375 |
$rec_num++; |
367 |
$rec_num++; |
376 |
if ($progress_interval and (0 == ($rec_num % $progress_interval))) { |
368 |
if ($progress_interval and (0 == ($rec_num % $progress_interval))) { |
377 |
&$progress_callback($rec_num); |
369 |
&$progress_callback($rec_num); |
378 |
} |
370 |
} |
379 |
my ($marc_record, $charset_guessed, $char_errors) = |
|
|
380 |
MarcToUTF8Record($marc_blob, $marc_type, $encoding); |
381 |
|
382 |
$encoding = $charset_guessed unless $encoding; |
383 |
|
371 |
|
384 |
ModifyRecordWithTemplate( $marc_modification_template, $marc_record ) if ( $marc_modification_template ); |
372 |
ModifyRecordWithTemplate( $marc_modification_template, $marc_record ) if ( $marc_modification_template ); |
385 |
|
373 |
|
386 |
my $import_record_id; |
374 |
my $import_record_id; |
387 |
if (scalar($marc_record->fields()) == 0) { |
375 |
if (scalar($marc_record->fields()) == 0) { |
388 |
push @invalid_records, $marc_blob; |
376 |
push @invalid_records, $marc_record; |
389 |
} else { |
377 |
} else { |
390 |
|
378 |
|
391 |
# Normalize the record so it doesn't have separated diacritics |
379 |
# Normalize the record so it doesn't have separated diacritics |
Lines 1425-1430
sub SetImportRecordBiblioMatch {
Link Here
|
1425 |
SetImportRecordMatches( $import_record_id, $matchedBiblioStub ); |
1413 |
SetImportRecordMatches( $import_record_id, $matchedBiblioStub ); |
1426 |
} |
1414 |
} |
1427 |
|
1415 |
|
|
|
1416 |
=head RecordsFromISO2709File |
1417 |
|
1418 |
my $records = C4::ImportBatch::RecordsFromISO2709File($input_file, $record_type, $encoding); |
1419 |
|
1420 |
Reads ISO2709 binary porridge from the given file and creates MARC::Record-objects out of it. |
1421 |
|
1422 |
@PARAM1, String, absolute path to the ISO2709 file. |
1423 |
@PARAM2, String, see stage_file.pl |
1424 |
@PARAM3, String, should be utf8 |
1425 |
|
1426 |
=cut |
1427 |
|
1428 |
sub RecordsFromISO2709File { |
1429 |
my ($input_file, $record_type, $encoding) = @_; |
1430 |
my $errors; |
1431 |
|
1432 |
my $marc_type = C4::Context->preference('marcflavour'); |
1433 |
$marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth'); |
1434 |
|
1435 |
open IN, "<$input_file" or die "$0: cannot open input file $input_file: $!\n"; |
1436 |
my @marc_records; |
1437 |
$/ = "\035"; |
1438 |
while (<IN>) { |
1439 |
s/^\s+//; |
1440 |
s/\s+$//; |
1441 |
next unless $_; # skip if record has only whitespace, as might occur |
1442 |
# if file includes newlines between each MARC record |
1443 |
my ($marc_record, $charset_guessed, $char_errors) = MarcToUTF8Record($_, $marc_type, $encoding); |
1444 |
push @marc_records, $marc_record; |
1445 |
if ($charset_guessed ne $encoding) { |
1446 |
$errors = '' unless $errors; |
1447 |
$errors .= "Unexpected charset $charset_guessed, expecting $encoding\n"; |
1448 |
} |
1449 |
} |
1450 |
close IN; |
1451 |
return ($errors, \@marc_records); |
1452 |
} |
1453 |
|
1454 |
=head RecordsFromMARCXMLFile |
1455 |
|
1456 |
my $records = C4::ImportBatch::RecordsFromMARCXMLFile($input_file, $encoding); |
1457 |
|
1458 |
Creates MARC::Record-objects out of the given MARCXML-file. |
1459 |
|
1460 |
@PARAM1, String, absolute path to the ISO2709 file. |
1461 |
@PARAM2, String, should be utf8 |
1462 |
|
1463 |
=cut |
1464 |
|
1465 |
sub RecordsFromMARCXMLFile { |
1466 |
my ($filename, $encoding) = @_; |
1467 |
my $batch = MARC::File::XML->in( $filename ); |
1468 |
my @marcRecords; |
1469 |
while (my $record = $batch->next($encoding)) { #How incredibly hard can be these MARC-libraries be to use? |
1470 |
push @marcRecords, $record; |
1471 |
} |
1472 |
return \@marcRecords; |
1473 |
} |
1428 |
|
1474 |
|
1429 |
# internal functions |
1475 |
# internal functions |
1430 |
|
1476 |
|