Bugzilla – Attachment 170703 Details for
Bug 37478
bulkmarcimport.pl can die on bad records
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 37478: Add strict mode to bulkmarcimport
Bug-37478-Add-strict-mode-to-bulkmarcimport.patch (text/plain), 2.93 KB, created by
David Nind
on 2024-08-26 10:43:49 UTC
(
hide
)
Description:
Bug 37478: Add strict mode to bulkmarcimport
Filename:
MIME Type:
Creator:
David Nind
Created:
2024-08-26 10:43:49 UTC
Size:
2.93 KB
patch
obsolete
>From 940afa9ba858b41bf8008b90c61730f48e8419fd Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Thu, 25 Jul 2024 16:37:17 +0000 >Subject: [PATCH] Bug 37478: Add strict mode to bulkmarcimport > >This patch adds a conversion from MARC -> XML -> MARC to catch any parsing errors. >If errors are found, we then lint the record to catch any problems, output the >warnings, and skip the record. > >To test: >1 - Download the sample records from this bug report >2 - perl misc/migration_tools/bulkmarcimport.pl -b --file=520_nosubfield.mrc -v > fails! >3 - perl misc/migration_tools/bulkmarcimport.pl -b --file=003_subfielda.mrc -v > fails! >4 - Apply patch >5 - Repeat 2 & 3 - no change >6 - Add -st switch to the commands: > perl misc/migration_tools/bulkmarcimport.pl -b --file=520_nosubfield.mrc -v -st > perl misc/migration_tools/bulkmarcimport.pl -b --file=003_subfielda.mrc -v -st >7 - The records are now skipped, and the script completes >8 - Confirm the warnings generated are useful >9 - Sign off! > >Signed-off-by: David Nind <david@davidnind.com> >--- > misc/migration_tools/bulkmarcimport.pl | 17 +++++++++++++++++ > 1 file changed, 17 insertions(+) > >diff --git a/misc/migration_tools/bulkmarcimport.pl b/misc/migration_tools/bulkmarcimport.pl >index 8161a0bb0a..eaed2a2890 100755 >--- a/misc/migration_tools/bulkmarcimport.pl >+++ b/misc/migration_tools/bulkmarcimport.pl >@@ -9,6 +9,7 @@ use Modern::Perl; > use MARC::File::USMARC; > use MARC::File::XML; > use MARC::Batch; >+use MARC::Lint; > use Encode; > > use Koha::Script; >@@ -75,6 +76,7 @@ my $framework = ''; > my $localcust; > my $marc_mod_template = ''; > my $marc_mod_template_id = -1; >+my $strict_mode; > $| = 1; > > GetOptions( >@@ -111,6 +113,7 @@ GetOptions( > 'framework=s' => \$framework, > 'custom:s' => \$localcust, > 'marcmodtemplate:s' => \$marc_mod_template, >+ 'st|strict' => \$strict_mode, > ); > > $biblios ||= !$authorities; >@@ -314,6 +317,7 @@ my $record_number = 0; > my $logger = Koha::Logger->get; > my $schema = Koha::Database->schema; > my $marc_records = []; >+my $lint = MARC::Lint->new; > RECORD: while () { > my $record; > $record_number++; >@@ -333,6 +337,19 @@ RECORD: while () { > } > if ($record) { > >+ if ($strict_mode) { >+ my $xml = $record->as_xml_record(); >+ eval { MARC::Record::new_from_xml( $xml, 'UTF-8', "MARC21" ); }; >+ if ($@) { >+ print "Record $record_number generated invalid xml:\n"; >+ $lint->check_record($record); >+ foreach my $warning ( $lint->warnings ) { >+ print " " . $warning . "\n"; >+ } >+ print " Record skipped!"; >+ next; >+ } >+ } > # transcode the record to UTF8 if needed & applicable. > if ( $record->encoding() eq 'MARC-8' and not $skip_marc8_conversion ) { > my ( $guessed_charset, $charset_errors ); >-- >2.39.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 37478
:
169598
|
169599
|
169600
|
170601
|
170703
|
170704
|
173831
|
173832
|
173833