Lines 413-436
sub BatchStageMarcRecords {
Link Here
|
413 |
my $num_items = 0; |
413 |
my $num_items = 0; |
414 |
# FIXME - for now, we're dealing only with bibs |
414 |
# FIXME - for now, we're dealing only with bibs |
415 |
my $rec_num = 0; |
415 |
my $rec_num = 0; |
416 |
foreach my $marc_blob (split(/\x1D/, $marc_records)) { |
416 |
foreach my $marc_record (@$marc_records) { |
417 |
$marc_blob =~ s/^\s+//g; |
|
|
418 |
$marc_blob =~ s/\s+$//g; |
419 |
next unless $marc_blob; |
420 |
$rec_num++; |
417 |
$rec_num++; |
421 |
if ($progress_interval and (0 == ($rec_num % $progress_interval))) { |
418 |
if ($progress_interval and (0 == ($rec_num % $progress_interval))) { |
422 |
&$progress_callback($rec_num); |
419 |
&$progress_callback($rec_num); |
423 |
} |
420 |
} |
424 |
my ($marc_record, $charset_guessed, $char_errors) = |
|
|
425 |
MarcToUTF8Record($marc_blob, $marc_type, $encoding); |
426 |
|
427 |
$encoding = $charset_guessed unless $encoding; |
428 |
|
421 |
|
429 |
ModifyRecordWithTemplate( $marc_modification_template, $marc_record ) if ( $marc_modification_template ); |
422 |
ModifyRecordWithTemplate( $marc_modification_template, $marc_record ) if ( $marc_modification_template ); |
430 |
|
423 |
|
431 |
my $import_record_id; |
424 |
my $import_record_id; |
432 |
if (scalar($marc_record->fields()) == 0) { |
425 |
if (scalar($marc_record->fields()) == 0) { |
433 |
push @invalid_records, $marc_blob; |
426 |
push @invalid_records, $marc_record; |
434 |
} else { |
427 |
} else { |
435 |
|
428 |
|
436 |
# Normalize the record so it doesn't have separated diacritics |
429 |
# Normalize the record so it doesn't have separated diacritics |
Lines 1448-1454
sub GetImportRecordMatches {
Link Here
|
1448 |
|
1441 |
|
1449 |
} |
1442 |
} |
1450 |
|
1443 |
|
1451 |
|
|
|
1452 |
=head2 SetImportRecordMatches |
1444 |
=head2 SetImportRecordMatches |
1453 |
|
1445 |
|
1454 |
SetImportRecordMatches($import_record_id, @matches); |
1446 |
SetImportRecordMatches($import_record_id, @matches); |
Lines 1471-1476
sub SetImportRecordMatches {
Link Here
|
1471 |
} |
1463 |
} |
1472 |
} |
1464 |
} |
1473 |
|
1465 |
|
|
|
1466 |
=head2 RecordsFromISO2709File |
1467 |
|
1468 |
my ($errors, $records) = C4::ImportBatch::RecordsFromISO2709File($input_file, $record_type, $encoding); |
1469 |
|
1470 |
Reads ISO2709 binary porridge from the given file and creates MARC::Record-objects out of it. |
1471 |
|
1472 |
@PARAM1, String, absolute path to the ISO2709 file. |
1473 |
@PARAM2, String, see stage_file.pl |
1474 |
@PARAM3, String, should be utf8 |
1475 |
|
1476 |
=cut |
1477 |
|
1478 |
sub RecordsFromISO2709File { |
1479 |
my ($input_file, $record_type, $encoding) = @_; |
1480 |
my $errors; |
1481 |
|
1482 |
my $marc_type = C4::Context->preference('marcflavour'); |
1483 |
$marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth'); |
1484 |
|
1485 |
open IN, "<$input_file" or die "$0: cannot open input file $input_file: $!\n"; |
1486 |
my @marc_records; |
1487 |
$/ = "\035"; |
1488 |
while (<IN>) { |
1489 |
s/^\s+//; |
1490 |
s/\s+$//; |
1491 |
next unless $_; # skip if record has only whitespace, as might occur |
1492 |
# if file includes newlines between each MARC record |
1493 |
my ($marc_record, $charset_guessed, $char_errors) = MarcToUTF8Record($_, $marc_type, $encoding); |
1494 |
push @marc_records, $marc_record; |
1495 |
if ($charset_guessed ne $encoding) { |
1496 |
$errors = '' unless $errors; |
1497 |
$errors .= "Unexpected charset $charset_guessed, expecting $encoding\n"; |
1498 |
} |
1499 |
} |
1500 |
close IN; |
1501 |
return ($errors, \@marc_records); |
1502 |
} |
1503 |
|
1504 |
=head2 RecordsFromMARCXMLFile |
1505 |
|
1506 |
my ($errors, $records) = C4::ImportBatch::RecordsFromMARCXMLFile($input_file, $encoding); |
1507 |
|
1508 |
|
1509 |
|
1510 |
Creates MARC::Record-objects out of the given MARCXML-file. |
1511 |
|
1512 |
@PARAM1, String, absolute path to the ISO2709 file. |
1513 |
@PARAM2, String, should be utf8 |
1514 |
|
1515 |
=cut |
1516 |
|
1517 |
sub RecordsFromMARCXMLFile { |
1518 |
my ( $filename, $encoding ) = @_; |
1519 |
my $batch = MARC::File::XML->in( $filename ); |
1520 |
my @marcRecords; |
1521 |
my @errors; |
1522 |
do { |
1523 |
eval { |
1524 |
my $record = $batch->next($encoding); |
1525 |
push @marcRecords, $record if $record; |
1526 |
}; |
1527 |
if ($@) { |
1528 |
push @errors, $@; |
1529 |
} |
1530 |
} while( $record ); |
1531 |
return (\@errors, \@marcRecords); |
1532 |
} |
1474 |
|
1533 |
|
1475 |
# internal functions |
1534 |
# internal functions |
1476 |
|
1535 |
|