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