From 95b5c50d9b5d7237e009eeda466869562652b88e Mon Sep 17 00:00:00 2001 From: Olli-Antti Kivilahti Date: Thu, 24 Sep 2015 09:01:19 +0300 Subject: [PATCH] Bug 10407 - allow MARCXML records to be imported via Koha's GUI - Catch deadly Record-level errors. --- C4/ImportBatch.pm | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm index d013680..4be731a 100644 --- a/C4/ImportBatch.pm +++ b/C4/ImportBatch.pm @@ -1415,7 +1415,7 @@ sub SetImportRecordBiblioMatch { =head RecordsFromISO2709File - my $records = C4::ImportBatch::RecordsFromISO2709File($input_file, $record_type, $encoding); + my ($errors, $records) = C4::ImportBatch::RecordsFromISO2709File($input_file, $record_type, $encoding); Reads ISO2709 binary porridge from the given file and creates MARC::Record-objects out of it. @@ -1453,7 +1453,7 @@ sub RecordsFromISO2709File { =head RecordsFromMARCXMLFile - my $records = C4::ImportBatch::RecordsFromMARCXMLFile($input_file, $encoding); + my ($errors, $records) = C4::ImportBatch::RecordsFromMARCXMLFile($input_file, $encoding); Creates MARC::Record-objects out of the given MARCXML-file. @@ -1466,10 +1466,21 @@ sub RecordsFromMARCXMLFile { my ($filename, $encoding) = @_; my $batch = MARC::File::XML->in( $filename ); my @marcRecords; - while (my $record = $batch->next($encoding)) { #How incredibly hard can be these MARC-libraries be to use? - push @marcRecords, $record; - } - return \@marcRecords; + my @errors; + my $record; + + do { + eval { + $record = $batch->next($encoding); + push @marcRecords, $record if $record; + }; + if ($@) { + push @errors, $@; + } + + } while ($@ || $record); + + return (\@errors, \@marcRecords); } # internal functions -- 1.9.1