Lines 1495-1501
Returns two array refs.
Link Here
|
1495 |
=cut |
1495 |
=cut |
1496 |
|
1496 |
|
1497 |
sub RecordsFromISO2709File { |
1497 |
sub RecordsFromISO2709File { |
1498 |
my ($input_file, $record_type, $encoding) = @_; |
1498 |
my ($input_file, $record_type, $encoding, $offset, $count) = @_; |
|
|
1499 |
$offset ||= 0; |
1499 |
my @errors; |
1500 |
my @errors; |
1500 |
|
1501 |
|
1501 |
my $marc_type = C4::Context->preference('marcflavour'); |
1502 |
my $marc_type = C4::Context->preference('marcflavour'); |
Lines 1507-1512
sub RecordsFromISO2709File {
Link Here
|
1507 |
while (<IN>) { |
1508 |
while (<IN>) { |
1508 |
s/^\s+//; |
1509 |
s/^\s+//; |
1509 |
s/\s+$//; |
1510 |
s/\s+$//; |
|
|
1511 |
next unless $i >= $offset; |
1510 |
next unless $_; # skip if record has only whitespace, as might occur |
1512 |
next unless $_; # skip if record has only whitespace, as might occur |
1511 |
# if file includes newlines between each MARC record |
1513 |
# if file includes newlines between each MARC record |
1512 |
my ($marc_record, $charset_guessed, $char_errors) = MarcToUTF8Record($_, $marc_type, $encoding); |
1514 |
my ($marc_record, $charset_guessed, $char_errors) = MarcToUTF8Record($_, $marc_type, $encoding); |
Lines 1515-1520
sub RecordsFromISO2709File {
Link Here
|
1515 |
push @errors, |
1517 |
push @errors, |
1516 |
"Unexpected charset $charset_guessed, expecting $encoding"; |
1518 |
"Unexpected charset $charset_guessed, expecting $encoding"; |
1517 |
} |
1519 |
} |
|
|
1520 |
last unless ( !$count && !$offset ) || ( $count && $i < $count + $offset ); |
1518 |
} |
1521 |
} |
1519 |
close IN; |
1522 |
close IN; |
1520 |
return ( \@errors, \@marc_records ); |
1523 |
return ( \@errors, \@marc_records ); |
Lines 1522-1528
sub RecordsFromISO2709File {
Link Here
|
1522 |
|
1525 |
|
1523 |
=head2 RecordsFromMARCXMLFile |
1526 |
=head2 RecordsFromMARCXMLFile |
1524 |
|
1527 |
|
1525 |
my ($errors, $records) = C4::ImportBatch::RecordsFromMARCXMLFile($input_file, $encoding); |
1528 |
my ($errors, $records) = C4::ImportBatch::RecordsFromMARCXMLFile($input_file, $encoding, $offset, $count); |
1526 |
|
1529 |
|
1527 |
Creates MARC::Record-objects out of the given MARCXML-file. |
1530 |
Creates MARC::Record-objects out of the given MARCXML-file. |
1528 |
|
1531 |
|
Lines 1534-1549
Returns two array refs.
Link Here
|
1534 |
=cut |
1537 |
=cut |
1535 |
|
1538 |
|
1536 |
sub RecordsFromMARCXMLFile { |
1539 |
sub RecordsFromMARCXMLFile { |
1537 |
my ( $filename, $encoding ) = @_; |
1540 |
my ( $filename, $encoding, $offset, $count ) = @_; |
|
|
1541 |
$offset ||= 0; |
1542 |
|
1543 |
$offset = 100; |
1544 |
$count = 100; |
1538 |
my $batch = MARC::File::XML->in( $filename ); |
1545 |
my $batch = MARC::File::XML->in( $filename ); |
|
|
1546 |
|
1539 |
my ( @marcRecords, @errors, $record ); |
1547 |
my ( @marcRecords, @errors, $record ); |
|
|
1548 |
my $i = 0; |
1540 |
do { |
1549 |
do { |
1541 |
eval { $record = $batch->next( $encoding ); }; |
1550 |
eval { $record = $batch->next( $encoding ); }; |
1542 |
if ($@) { |
1551 |
if ($@) { |
1543 |
push @errors, $@; |
1552 |
push( @errors, $@ ) if $i >= $offset; |
1544 |
} |
1553 |
} |
1545 |
push @marcRecords, $record if $record; |
1554 |
push @marcRecords, $record if $record && $i >= $offset; |
1546 |
} while( $record ); |
1555 |
$i++; |
|
|
1556 |
} while( $record && ( ( !$count && !$offset ) || ( $count && $i < $count + $offset ) ) ); |
1547 |
return (\@errors, \@marcRecords); |
1557 |
return (\@errors, \@marcRecords); |
1548 |
} |
1558 |
} |
1549 |
|
1559 |
|
1550 |
- |
|
|