Lines 26-31
use C4::Charset;
Link Here
|
26 |
use C4::Items; |
26 |
use C4::Items; |
27 |
use C4::MarcModificationTemplates; |
27 |
use C4::MarcModificationTemplates; |
28 |
|
28 |
|
|
|
29 |
use Encode; |
29 |
use YAML; |
30 |
use YAML; |
30 |
use Unicode::Normalize; |
31 |
use Unicode::Normalize; |
31 |
use Time::HiRes qw(gettimeofday); |
32 |
use Time::HiRes qw(gettimeofday); |
Lines 48-53
my $framework = '';
Link Here
|
48 |
my $localcust; |
49 |
my $localcust; |
49 |
my $marc_mod_template = ''; |
50 |
my $marc_mod_template = ''; |
50 |
my $marc_mod_template_id = -1; |
51 |
my $marc_mod_template_id = -1; |
|
|
52 |
my ($incoming_filter, $local_filter); |
53 |
|
51 |
|
54 |
|
52 |
$|=1; |
55 |
$|=1; |
53 |
|
56 |
|
Lines 85-93
GetOptions(
Link Here
|
85 |
'framework=s' => \$framework, |
88 |
'framework=s' => \$framework, |
86 |
'custom:s' => \$localcust, |
89 |
'custom:s' => \$localcust, |
87 |
'marcmodtemplate:s' => \$marc_mod_template, |
90 |
'marcmodtemplate:s' => \$marc_mod_template, |
|
|
91 |
'incomingfilter=s' => \$incoming_filter, |
92 |
'localfilter=s' => \$local_filter, |
88 |
); |
93 |
); |
89 |
$biblios ||= !$authorities; |
94 |
$biblios ||= !$authorities; |
90 |
$insert ||= !$update; |
95 |
$insert ||= !$update; |
|
|
96 |
|
97 |
$incoming_filter = decode('UTF-8', $incoming_filter) if ($incoming_filter); |
98 |
$local_filter = decode('UTF-8', $local_filter) if ($local_filter); |
99 |
|
91 |
my $writemode = ($append) ? "a" : "w"; |
100 |
my $writemode = ($append) ? "a" : "w"; |
92 |
|
101 |
|
93 |
pod2usage( -msg => "\nYou must specify either --biblios or --authorities, not both.\n", -exitval ) if $biblios && $authorities; |
102 |
pod2usage( -msg => "\nYou must specify either --biblios or --authorities, not both.\n", -exitval ) if $biblios && $authorities; |
Lines 310-315
RECORD: while ( ) {
Link Here
|
310 |
# search for duplicates (based on Local-number) |
319 |
# search for duplicates (based on Local-number) |
311 |
my $originalid; |
320 |
my $originalid; |
312 |
$originalid = GetRecordId( $record, $tagid, $subfieldid ); |
321 |
$originalid = GetRecordId( $record, $tagid, $subfieldid ); |
|
|
322 |
|
323 |
if ($incoming_filter) { |
324 |
my ($fieldsubfieldtag, $value) = split('=', $incoming_filter); |
325 |
die "Unable to get field/subfield and value to discard record (-incomingfilter=$incoming_filter)\n" unless ($fieldsubfieldtag && $value); |
326 |
my ($fieldtag, $subfieldtag) = split('\$', $fieldsubfieldtag); |
327 |
die "Unable to get field and subfield to discard record (-incomingfilter=$incoming_filter)\n" unless ($fieldtag && $subfieldtag); |
328 |
foreach my $field ($record->field($fieldtag)) { |
329 |
foreach my $subfield ($field->subfield($subfieldtag)) { |
330 |
if ($subfield eq $value) { |
331 |
$debug and warn "Discarding record (incoming record contains $fieldsubfieldtag = $value)\n"; |
332 |
printlog({id => $id || $originalid || $match, op => "incomingfilter", status => "REJECTED"}) if ($logfile); |
333 |
next RECORD; |
334 |
} |
335 |
} |
336 |
} |
337 |
} |
338 |
|
313 |
if ($match) { |
339 |
if ($match) { |
314 |
require C4::Search; |
340 |
require C4::Search; |
315 |
my $query = build_query( $match, $record ); |
341 |
my $query = build_query( $match, $record ); |
Lines 327-332
RECORD: while ( ) {
Link Here
|
327 |
my $marcrecord = C4::Search::new_record_from_zebra( $server, $results->[0] ); |
353 |
my $marcrecord = C4::Search::new_record_from_zebra( $server, $results->[0] ); |
328 |
SetUTF8Flag($marcrecord); |
354 |
SetUTF8Flag($marcrecord); |
329 |
$id = GetRecordId( $marcrecord, $tagid, $subfieldid ); |
355 |
$id = GetRecordId( $marcrecord, $tagid, $subfieldid ); |
|
|
356 |
|
357 |
if ($local_filter) { |
358 |
my ($fieldsubfieldtag, $value) = split('=', $local_filter); |
359 |
die "Unable to get field/subfield and value to discard record (-localfilter=$local_filter)\n" unless ($fieldsubfieldtag && $value); |
360 |
my ($fieldtag, $subfieldtag) = split('\$', $fieldsubfieldtag); |
361 |
die "Unable to get field and subfield to discard record (-localfilter=$local_filter)\n" unless ($fieldtag && $subfieldtag); |
362 |
foreach my $field ($marcrecord->field($fieldtag)) { |
363 |
foreach my $subfield ($field->subfield($subfieldtag)) { |
364 |
if ($subfield eq $value) { |
365 |
$debug and warn "Discarding record (koha record contains $fieldsubfieldtag = $value)\n"; |
366 |
printlog({id => $id || $originalid || $match, op => "localfilter", status => "REJECTED"}) if ($logfile); |
367 |
next RECORD; |
368 |
} |
369 |
} |
370 |
} |
371 |
} |
372 |
|
330 |
if ( $authorities && $marcFlavour ) { |
373 |
if ( $authorities && $marcFlavour ) { |
331 |
#Skip if authority in database is the same as the on in database |
374 |
#Skip if authority in database is the same as the on in database |
332 |
if ( $marcrecord->field('005') && $record->field('005') && |
375 |
if ( $marcrecord->field('005') && $record->field('005') && |
Lines 843-848
modification template to apply as the MARC records are imported (these
Link Here
|
843 |
templates are created in the "MARC modification templates" tool in Koha). |
886 |
templates are created in the "MARC modification templates" tool in Koha). |
844 |
If not specified, no MARC modification templates are used (default). |
887 |
If not specified, no MARC modification templates are used (default). |
845 |
|
888 |
|
|
|
889 |
=item B<-incomingfilter>='<FIELD>$<SUBFIELD>=<VALUE>' |
890 |
|
891 |
This parameter allows you to prevent this script from importing a record when a |
892 |
given value is present in the record to be imported. |
893 |
|
894 |
=item B<-localfilter>='<FIELD>$<SUBFIELD>=<VALUE>' |
895 |
|
896 |
This parameter allows you to prevent this script from importing a record when a |
897 |
given value is present in the koha record that would be replaced by the record |
898 |
to be imported. |
899 |
|
900 |
|
846 |
=back |
901 |
=back |
847 |
|
902 |
|
848 |
=cut |
903 |
=cut |
849 |
- |
|
|