Bugzilla – Attachment 108503 Details for
Bug 26235
Allow to skip records when using bulkmarcimport.pl
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
MT26327: Allow to skip records when using bulkmarcimport.pl
MT26327-Allow-to-skip-records-when-using-bulkmarci.patch (text/plain), 5.92 KB, created by
Matthias Meusburger
on 2020-08-18 13:19:51 UTC
(
hide
)
Description:
MT26327: Allow to skip records when using bulkmarcimport.pl
Filename:
MIME Type:
Creator:
Matthias Meusburger
Created:
2020-08-18 13:19:51 UTC
Size:
5.92 KB
patch
obsolete
>From a0b31e4640c66c3406035343e6f9c64b4ec0fe43 Mon Sep 17 00:00:00 2001 >From: Matthias Meusburger <matthias.meusburger@biblibre.com> >Date: Mon, 10 Feb 2020 16:58:53 +0100 >Subject: [PATCH] MT26327: Allow to skip records when using bulkmarcimport.pl > > This patch allows to prevent records from being imported by bulkmarcimport.pl >when a given value is present. > >Two options are added: > > -incomingfilter: prevent the script from importing a record when a given value > is present in the record to be imported. > > -localfilter: prevent the script from importing a record when a given value is > present in the koha record that would be replaced by the record > to be imported. > >They both accept the following specificaton: > >'<FIELD>$<SUBFIELD>=<VALUE>' > >Test plan: > > 1) Apply this patch > > 2) Launch bulkmarcimport.pl with the following option: > -incomingfilter='152$b=rameau' > > 3) Check that the incoming records with at least a 152$b equal to 'rameau' are > skipped. > The following message will be displayed for each skipped record if debug > is enabled: Discarding record (incoming record contains 152$b = rameau) > > 4) Repeat step 2 with localfilter: -localfilter='152$b=rameau' > Check that incoming records are skipped when the koha record they would > replace contains at least a 152$b equal to 'rameau'. > > 5) Launch bulkmarcimport.pl with an invalid configuration, like: > -incomingfilter='incorrect_specification' or > -localfilter='incorrect_specification' > > 6) Check that an error message is displayed and that the script exits. > >https://bugs.koha-community.org/show_bug.cgi?id=26235 >--- > misc/migration_tools/bulkmarcimport.pl | 51 ++++++++++++++++++++++++++++++++++ > 1 file changed, 51 insertions(+) > >diff --git a/misc/migration_tools/bulkmarcimport.pl b/misc/migration_tools/bulkmarcimport.pl >index 6e9ea0b..5b9c201 100755 >--- a/misc/migration_tools/bulkmarcimport.pl >+++ b/misc/migration_tools/bulkmarcimport.pl >@@ -26,6 +26,7 @@ use C4::Charset; > use C4::Items; > use C4::MarcModificationTemplates; > >+use Encode; > use YAML; > use Unicode::Normalize; > use Time::HiRes qw(gettimeofday); >@@ -48,6 +49,8 @@ my $framework = ''; > my $localcust; > my $marc_mod_template = ''; > my $marc_mod_template_id = -1; >+my ($incoming_filter, $local_filter); >+ > > $|=1; > >@@ -85,9 +88,15 @@ GetOptions( > 'framework=s' => \$framework, > 'custom:s' => \$localcust, > 'marcmodtemplate:s' => \$marc_mod_template, >+ 'incomingfilter=s' => \$incoming_filter, >+ 'localfilter=s' => \$local_filter, > ); > $biblios ||= !$authorities; > $insert ||= !$update; >+ >+$incoming_filter = decode('UTF-8', $incoming_filter) if ($incoming_filter); >+$local_filter = decode('UTF-8', $local_filter) if ($local_filter); >+ > my $writemode = ($append) ? "a" : "w"; > > pod2usage( -msg => "\nYou must specify either --biblios or --authorities, not both.\n", -exitval ) if $biblios && $authorities; >@@ -291,6 +300,20 @@ RECORD: while ( ) { > } > } > SetUTF8Flag($record); >+ if ($incoming_filter) { >+ my ($fieldsubfieldtag, $value) = split('=', $incoming_filter); >+ die "Unable to get field/subfield and value to discard record (-incomingfilter=$incoming_filter)\n" unless ($fieldsubfieldtag && $value); >+ my ($fieldtag, $subfieldtag) = split('\$', $fieldsubfieldtag); >+ die "Unable to get field and subfield to discard record (-incomingfilter=$incoming_filter)\n" unless ($fieldtag && $subfieldtag); >+ foreach my $field ($record->field($fieldtag)) { >+ foreach my $subfield ($field->subfield($subfieldtag)) { >+ if ($subfield eq $value) { >+ $debug and warn "Discarding record (incoming record contains $fieldsubfieldtag = $value)\n"; >+ next RECORD; >+ } >+ } >+ } >+ } > if($marc_mod_template_id > 0) { > print "Modifying MARC\n" if $verbose; > ModifyRecordWithTemplate( $marc_mod_template_id, $record ); >@@ -328,6 +351,22 @@ RECORD: while ( ) { > my $marcrecord = C4::Search::new_record_from_zebra( $server, $results->[0] ); > SetUTF8Flag($marcrecord); > $id = GetRecordId( $marcrecord, $tagid, $subfieldid ); >+ >+ if ($local_filter) { >+ my ($fieldsubfieldtag, $value) = split('=', $local_filter); >+ die "Unable to get field/subfield and value to discard record (-localfilter=$local_filter)\n" unless ($fieldsubfieldtag && $value); >+ my ($fieldtag, $subfieldtag) = split('\$', $fieldsubfieldtag); >+ die "Unable to get field and subfield to discard record (-localfilter=$local_filter)\n" unless ($fieldtag && $subfieldtag); >+ foreach my $field ($marcrecord->field($fieldtag)) { >+ foreach my $subfield ($field->subfield($subfieldtag)) { >+ if ($subfield eq $value) { >+ $debug and warn "Discarding record (koha record contains $fieldsubfieldtag = $value)\n"; >+ next RECORD; >+ } >+ } >+ } >+ } >+ > if ( $authorities && $marcFlavour ) { > #Skip if authority in database is the same as the on in database > if ( $marcrecord->field('005') && $record->field('005') && >@@ -832,6 +871,18 @@ modification template to apply as the MARC records are imported (these > templates are created in the "MARC modification templates" tool in Koha). > If not specified, no MARC modification templates are used (default). > >+=item B<-incomingfilter>='<FIELD>$<SUBFIELD>=<VALUE>' >+ >+This parameter allows you to prevent this script from importing a record when a >+given value is present in the record to be imported. >+ >+=item B<-localfilter>='<FIELD>$<SUBFIELD>=<VALUE>' >+ >+This parameter allows you to prevent this script from importing a record when a >+given value is present in the koha record that would be replaced by the record >+to be imported. >+ >+ > =back > > =cut >-- >2.7.4
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 26235
:
108503
|
116404
|
116406