@@ -, +, @@ This patch allows to prevent records from being imported by bulkmarcimport.pl -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. 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. --- misc/migration_tools/bulkmarcimport.pl | 55 ++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) --- a/misc/migration_tools/bulkmarcimport.pl +++ a/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; @@ -310,6 +319,23 @@ RECORD: while ( ) { # search for duplicates (based on Local-number) my $originalid; $originalid = GetRecordId( $record, $tagid, $subfieldid ); + + 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"; + printlog({id => $id || $originalid || $match, op => "incomingfilter", status => "REJECTED"}) if ($logfile); + next RECORD; + } + } + } + } + if ($match) { require C4::Search; my $query = build_query( $match, $record ); @@ -327,6 +353,23 @@ 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"; + printlog({id => $id || $originalid || $match, op => "localfilter", status => "REJECTED"}) if ($logfile); + 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') && @@ -843,6 +886,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>='$=' + +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>='$=' + +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 --