View | Details | Raw Unified | Return to bug 26235
Collapse All | Expand All

(-)a/misc/migration_tools/bulkmarcimport.pl (-1 / +55 lines)
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 312-317 RECORD: while ( ) { Link Here
312
    # search for duplicates (based on Local-number)
321
    # search for duplicates (based on Local-number)
313
    my $originalid;
322
    my $originalid;
314
    $originalid = GetRecordId( $record, $tagid, $subfieldid );
323
    $originalid = GetRecordId( $record, $tagid, $subfieldid );
324
325
    if ($incoming_filter) {
326
        my ($fieldsubfieldtag, $value) = split('=', $incoming_filter);
327
        die "Unable to get field/subfield and value to discard record (-incomingfilter=$incoming_filter)\n" unless ($fieldsubfieldtag && $value);
328
        my ($fieldtag, $subfieldtag) = split('\$', $fieldsubfieldtag);
329
        die "Unable to get field and subfield to discard record (-incomingfilter=$incoming_filter)\n" unless ($fieldtag && $subfieldtag);
330
        foreach my $field ($record->field($fieldtag)) {
331
            foreach my $subfield ($field->subfield($subfieldtag)) {
332
                if ($subfield eq $value) {
333
                    $debug and warn "Discarding record (incoming record contains $fieldsubfieldtag = $value)\n";
334
                    printlog({id => $id || $originalid || $match, op => "incomingfilter", status => "REJECTED"}) if ($logfile);
335
                    next RECORD;
336
                }
337
            }
338
        }
339
    }
340
315
    if ($match) {
341
    if ($match) {
316
        require C4::Search;
342
        require C4::Search;
317
        my $query = build_query( $match, $record );
343
        my $query = build_query( $match, $record );
Lines 329-334 RECORD: while ( ) { Link Here
329
            my $marcrecord = C4::Search::new_record_from_zebra( $server, $results->[0] );
355
            my $marcrecord = C4::Search::new_record_from_zebra( $server, $results->[0] );
330
            SetUTF8Flag($marcrecord);
356
            SetUTF8Flag($marcrecord);
331
            $id = GetRecordId( $marcrecord, $tagid, $subfieldid );
357
            $id = GetRecordId( $marcrecord, $tagid, $subfieldid );
358
359
            if ($local_filter) {
360
                my ($fieldsubfieldtag, $value) = split('=', $local_filter);
361
                die "Unable to get field/subfield and value to discard record (-localfilter=$local_filter)\n" unless ($fieldsubfieldtag && $value);
362
                my ($fieldtag, $subfieldtag) = split('\$', $fieldsubfieldtag);
363
                die "Unable to get field and subfield to discard record (-localfilter=$local_filter)\n" unless ($fieldtag && $subfieldtag);
364
                foreach my $field ($marcrecord->field($fieldtag)) {
365
                    foreach my $subfield ($field->subfield($subfieldtag)) {
366
                        if ($subfield eq $value) {
367
                            $debug and warn "Discarding record (koha record contains $fieldsubfieldtag = $value)\n";
368
                            printlog({id => $id || $originalid || $match, op => "localfilter", status => "REJECTED"}) if ($logfile);
369
                            next RECORD;
370
                        }
371
                    }
372
                }
373
            }
374
332
            if ( $authorities && $marcFlavour ) {
375
            if ( $authorities && $marcFlavour ) {
333
                #Skip if authority in database is the same as the on in database
376
                #Skip if authority in database is the same as the on in database
334
                if ( $marcrecord->field('005') && $record->field('005') &&
377
                if ( $marcrecord->field('005') && $record->field('005') &&
Lines 823-828 modification template to apply as the MARC records are imported (these Link Here
823
templates are created in the "MARC modification templates" tool in Koha).
866
templates are created in the "MARC modification templates" tool in Koha).
824
If not specified, no MARC modification templates are used (default).
867
If not specified, no MARC modification templates are used (default).
825
868
869
=item B<-incomingfilter>='<FIELD>$<SUBFIELD>=<VALUE>'
870
871
This parameter allows you to prevent this script from importing a record when a
872
given value is present in the record to be imported.
873
874
=item B<-localfilter>='<FIELD>$<SUBFIELD>=<VALUE>'
875
876
This parameter allows you to prevent this script from importing a record when a
877
given value is present in the koha record that would be replaced by the record
878
to be imported.
879
880
826
=back
881
=back
827
882
828
=cut
883
=cut
829
- 

Return to bug 26235