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

(-)a/C4/AuthoritiesMarc.pm (-27 / +115 lines)
Lines 841-882 Comments : an improvement would be to return All the records that match. Link Here
841
841
842
=cut
842
=cut
843
843
844
sub _find_duplicate_authority_try {
845
    my ($try, $authorityfield, $authtypecode) = @_;
846
847
    my $filtervalues = qr([\001-\040\Q!'"`#$%&*+,-./:;<=>?@(){[}_|~\E\]]);
848
849
    my $op = 'and';
850
    if (C4::Context->preference('UseQueryParser')) {
851
        my $QParser = C4::Context->queryparser;
852
        if ($QParser) {
853
            $op = '&&';
854
        } else {
855
            $op = 'and';
856
        }
857
    }
858
859
    # build a request for SearchAuthorities
860
    my $query = "at=$authtypecode";
861
862
    my $duplicaterecord;
863
    if ($try->{field} and $try->{subfields}) {
864
        foreach my $s (@{ $try->{subfields} }) {
865
            my $v = $authorityfield->subfield($s);
866
            if ($v) {
867
                $v =~ s/$filtervalues/ /g;
868
                $v =~ s/^\s*//;
869
                $v =~ s/\s*$//;
870
                $query .= qq/ $op $try->{index}="$v"/;
871
            }
872
        }
873
        my $maxresults = C4::Context->preference('FindDuplicateAuthorityMaxResults') || 10;
874
        my ($error, $results, $total_hits) =
875
            C4::Search::SimpleSearch($query, 0, $maxresults, ["authorityserver"]);
876
        return unless (!defined $error and @{$results});
877
878
        foreach my $result (@$results) {
879
            my $marcrecord =
880
              C4::Search::new_record_from_zebra( 'authorityserver', $result );
881
            my @marcfields = $marcrecord->field($try->{field});
882
            next if (scalar @marcfields == 0);
883
            my $stillmatch = 1;
884
            foreach my $marcfield (@marcfields) {
885
                foreach my $subfield (@{ $try->{subfields} }) {
886
                    my $authoritysubfield = $authorityfield->subfield($subfield);
887
                    my $marcsubfield = $marcfield->subfield($subfield);
888
                    if ( (defined $authoritysubfield xor defined $marcsubfield)
889
                      or (defined $authoritysubfield
890
                        and $authoritysubfield ne $marcsubfield)
891
                    ) {
892
                        $stillmatch = 0;
893
                        last;
894
                    }
895
                }
896
                last unless $stillmatch;
897
            }
898
            if ($stillmatch) {
899
                $duplicaterecord = $marcrecord;
900
                last;
901
            }
902
        }
903
    } else {
904
        foreach my $s ($authorityfield->subfields()) {
905
            next unless ($s->[0] =~ /[A-z]/);
906
            $s->[1] =~ s/$filtervalues/ /g;
907
            $query .= qq/ $op $try->{index}="$s->[1]"/;
908
        }
909
        my ($error, $results, $total_hits) =
910
            C4::Search::SimpleSearch( $query, 0, 1, ["authorityserver"] );
911
        if (!defined $error and @{$results}) {
912
            $duplicaterecord =
913
              C4::Search::new_record_from_zebra( 'authorityserver',
914
                $results->[0] );
915
        }
916
    }
917
918
    return $duplicaterecord;
919
}
920
844
sub FindDuplicateAuthority {
921
sub FindDuplicateAuthority {
922
    my ($record, $authtypecode) = @_;
923
924
    return unless $record;
925
926
    my $opts = C4::Context->preference('FindDuplicateAuthorityOptions');
927
    return unless $opts;
845
928
846
    my ($record,$authtypecode)=@_;
847
#    warn "IN for ".$record->as_formatted;
848
    my $dbh = C4::Context->dbh;
929
    my $dbh = C4::Context->dbh;
849
#    warn "".$record->as_formatted;
930
    my $sth = $dbh->prepare("
850
    my $sth = $dbh->prepare("select auth_tag_to_report from auth_types where authtypecode=?");
931
        SELECT auth_tag_to_report FROM auth_types WHERE authtypecode = ?
932
    ");
851
    $sth->execute($authtypecode);
933
    $sth->execute($authtypecode);
852
    my ($auth_tag_to_report) = $sth->fetchrow;
934
    my ($auth_tag_to_report) = $sth->fetchrow;
853
    $sth->finish;
935
    $sth->finish;
854
#     warn "record :".$record->as_formatted."  auth_tag_to_report :$auth_tag_to_report";
936
855
    # build a request for SearchAuthorities
937
    my $authorityfield = $record->field($auth_tag_to_report);
856
    my $QParser;
938
    return unless $authorityfield;
857
    $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
939
858
    my $op;
940
    my @tries;
859
    if ($QParser) {
941
    $opts =~ s/ //g;
860
        $op = '&&';
942
    foreach my $try (split /\|/, $opts) {
861
    } else {
943
        my ($index, $matchcheck) = split m#/#, $try;
862
        $op = 'and';
944
        my ($field, @subfields);
863
    }
945
        if ($matchcheck and length($matchcheck) > 3) {
864
    my $query='at:'.$authtypecode.' ';
946
            $field = substr $matchcheck, 0, 3;
865
    my $filtervalues=qr([\001-\040\Q!'"`#$%&*+,-./:;<=>?@(){[}_|~\E\]]);
947
            @subfields = split(//, substr($matchcheck, 3));
866
    if ($record->field($auth_tag_to_report)) {
867
        foreach ($record->field($auth_tag_to_report)->subfields()) {
868
            $_->[1]=~s/$filtervalues/ /g; $query.= " $op he:\"".$_->[1]."\"" if ($_->[0]=~/[A-z]/);
869
        }
948
        }
949
        push @tries, {
950
            index => $index,
951
            field => $field,
952
            subfields => \@subfields,
953
        };
870
    }
954
    }
871
    my ($error, $results, $total_hits) = C4::Search::SimpleSearch( $query, 0, 1, [ "authorityserver" ] );
955
872
    # there is at least 1 result => return the 1st one
956
    my $duplicaterecord;
873
    if (!defined $error && @{$results} ) {
957
    foreach my $try (@tries) {
874
        my $marcrecord = C4::Search::new_record_from_zebra(
958
        $duplicaterecord = _find_duplicate_authority_try($try, $authorityfield,
875
            'authorityserver',
959
            $authtypecode);
876
            $results->[0]
960
        last if $duplicaterecord;
877
        );
961
    }
878
        return $marcrecord->field('001')->data,BuildSummary($marcrecord,$marcrecord->field('001')->data,$authtypecode);
962
963
    if ($duplicaterecord) {
964
        my $authid = $duplicaterecord->field('001')->data;
965
        return $authid, BuildSummary($duplicaterecord, $authid, $authtypecode);
879
    }
966
    }
967
880
    # no result, returns nothing
968
    # no result, returns nothing
881
    return;
969
    return;
882
}
970
}
(-)a/installer/data/mysql/sysprefs.sql (+2 lines)
Lines 125-130 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
125
('FacetLabelTruncationLength','20',NULL,'Specify the facet max length in OPAC','Integer'),
125
('FacetLabelTruncationLength','20',NULL,'Specify the facet max length in OPAC','Integer'),
126
('FacetMaxCount','20',NULL,'Specify the max facet count for each category','Integer'),
126
('FacetMaxCount','20',NULL,'Specify the max facet count for each category','Integer'),
127
('FilterBeforeOverdueReport','0','','Do not run overdue report until filter selected','YesNo'),
127
('FilterBeforeOverdueReport','0','','Do not run overdue report until filter selected','YesNo'),
128
('FindDuplicateAuthorityOptions','he,wrdl',NULL,'Options to determine how to search for duplicate authorities. General form: "index1/XXXcc|index2" where indexX is the index where we want to search, and XXXcc the field(s) and subfield(s) we want to check for each search results (if omitted, the first result is returned as duplicate)','Free'),
129
('FindDuplicateAuthorityMaxResults','10',NULL'Maximum number of results fetched when searching a duplicate','Free'),
128
('FineNotifyAtCheckin','0',NULL,'If ON notify librarians of overdue fines on the items they are checking in.','YesNo'),
130
('FineNotifyAtCheckin','0',NULL,'If ON notify librarians of overdue fines on the items they are checking in.','YesNo'),
129
('finesCalendar','noFinesWhenClosed','ignoreCalendar|noFinesWhenClosed','Specify whether to use the Calendar in calculating duedates and fines','Choice'),
131
('finesCalendar','noFinesWhenClosed','ignoreCalendar|noFinesWhenClosed','Specify whether to use the Calendar in calculating duedates and fines','Choice'),
130
('FinesIncludeGracePeriod','1',NULL,'If enabled, fines calculations will include the grace period.','YesNo'),
132
('FinesIncludeGracePeriod','1',NULL,'If enabled, fines calculations will include the grace period.','YesNo'),
(-)a/installer/data/mysql/updatedatabase.pl (+15 lines)
Lines 9793-9798 if(CheckVersion($DBversion)) { Link Here
9793
    SetVersion($DBversion);
9793
    SetVersion($DBversion);
9794
}
9794
}
9795
9795
9796
$DBversion = "XXX";
9797
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
9798
    $dbh->do(q{
9799
        INSERT INTO systempreferences (variable, value, explanation, options, type)
9800
        VALUES ('FindDuplicateAuthorityOptions', 'he,wrdl', 'Options to determine how to search for duplicate authorities. General form: "index1/XXXcc#index2" where indexX is the index where we want to search, and XXXcc the field(s) and subfield(s) we want to check for each search results (if omitted, the first result is returned as duplicate)', NULL, 'Free');
9801
    });
9802
    $dbh->do(q{
9803
        INSERT INTO systempreferences (variable, value, explanation, options, type)
9804
        VALUES ('FindDuplicateAuthorityMaxResults', '10', 'Maximum number of results fetched when searching a duplicate', NULL, 'Integer');
9805
    });
9806
    print "Upgrade to $DBversion done (Bug 8994: Added system preferences FindDuplicateAuthorityOptions and FindDuplicateAuthorityMaxResults)\n";
9807
    SetVersion($DBversion);
9808
}
9809
9810
9796
=head1 FUNCTIONS
9811
=head1 FUNCTIONS
9797
9812
9798
=head2 TableExists($table)
9813
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref (-1 / +19 lines)
Lines 49-54 Authorities: Link Here
49
              defautl: "afrey50      ba0"
49
              defautl: "afrey50      ba0"
50
              type: textarea
50
              type: textarea
51
              class: code
51
              class: code
52
        -
53
            - pref: FindDuplicateAuthorityOptions
54
              class: long
55
            - '<br />Options to determine how to search for duplicate authorities when creating new authorities. General form: "index1/XXXcc | index2" where indexX is the index where we want to search, and XXXcc the field(s) and subfield(s) we want to check for each search results (if "XXXcc" part is omitted, the first result is returned as duplicate)'
56
            - '<br />Examples:'
57
            - '<br />- <tt>he,wrdl</tt>: Search in "he" index, do not check subfields data in search results, the first result is returned as a duplicate (default).'
58
            - '<br />- <tt>he,wrdl/2..ab</tt>: Search in "he" index, and compare 2XX$a and 2XX$b of search results with XXX$a and XXX$b of created authority (XXX is the "Authority field to copy"). The first matching authority is returned as duplicate.'
59
            - '<br />- <tt>he,wrdl | See,wrdl/4..ab</tt>: Search in "he" index and do not check subfields. If there is no results, search in "See" index and compare 4XX$a and 4XX$b of search results with XXX$a and XXX$b of created authority.'
60
            - '<br />Notes:'
61
            - '<br />- only authorities of the same type are returned by the search'
62
            - '<br />- the query to find authorities is build with subfields in syspref. For example <tt>he,wrdl/2..ab</tt> will search <tt>he,wrdl="2XX$a" and "he,wrdl="2XX$b"</tt>'
63
            - '<br />- if compared subfields are repeatable, only the first of each field is checked'
64
            - '<br />- spaces are insignificant'
65
            - '<br />- if value is empty, it disable authority duplicate searching.'
66
        -
67
            - 'Maximum number of results fetched when searching a duplicate:'
68
            - pref: FindDuplicateAuthorityMaxResults
69
              class: integer
70
            - "It's only used when FindDuplicateAuthorityOptions contains fields and subfields to check against (default: 10)"
52
    Linker:
71
    Linker:
53
        -
72
        -
54
            - Use the
73
            - Use the
55
- 

Return to bug 8994