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

(-)a/C4/AuthoritiesMarc.pm (-17 / +96 lines)
Lines 896-926 Comments : an improvement would be to return All the records that match. Link Here
896
896
897
=cut
897
=cut
898
898
899
sub _find_duplicate_authority_try {
900
    my ($try, $authorityfield, $authtypecode) = @_;
901
902
    my $filtervalues =
903
        qr([\001-\040\!\'\"\`\#\$\%\&\*\+,\-\./:;<=>\?\@\(\)\{\[\]\}_\|\~]);
904
905
    # build a request for SearchAuthorities
906
    my $query = "at=$authtypecode";
907
908
    foreach my $s ($authorityfield->subfields()) {
909
        next unless ($s->[0] =~ /[A-z]/);
910
        $s->[1] =~ s/$filtervalues/ /g;
911
        $query .= qq{ and $try->{index}="$s->[1]"};
912
    }
913
914
    my $duplicaterecord;
915
    if ($try->{field} and $try->{subfields}) {
916
        my $maxresults = C4::Context->preference('FindDuplicateMaxResults') || 10;
917
        my ($error, $results, $total_hits) =
918
            C4::Search::SimpleSearch($query, 0, $maxresults, ["authorityserver"]);
919
        return unless (!defined $error and @{$results});
920
921
        foreach my $result (@$results) {
922
            my $marcrecord = MARC::File::USMARC::decode($result);
923
            my @marcfields = $marcrecord->field($try->{field});
924
            next if (scalar @marcfields == 0);
925
            my $stillmatch = 1;
926
            foreach my $marcfield (@marcfields) {
927
                foreach my $subfield (@{ $try->{subfields} }) {
928
                    my $authoritysubfield = $authorityfield->subfield($subfield);
929
                    my $marcsubfield = $marcfield->subfield($subfield);
930
                    if ( (defined $authoritysubfield xor defined $marcsubfield)
931
                      or (defined $authoritysubfield
932
                        and $authoritysubfield ne $marcsubfield)
933
                    ) {
934
                        $stillmatch = 0;
935
                        last;
936
                    }
937
                }
938
                last unless $stillmatch;
939
            }
940
            if ($stillmatch) {
941
                $duplicaterecord = $marcrecord;
942
                last;
943
            }
944
        }
945
    } else {
946
        my ($error, $results, $total_hits) =
947
            C4::Search::SimpleSearch( $query, 0, 1, ["authorityserver"] );
948
        if (!defined $error and @{$results}) {
949
            $duplicaterecord = MARC::File::USMARC::decode($results->[0]);
950
        }
951
    }
952
953
    return $duplicaterecord;
954
}
955
899
sub FindDuplicateAuthority {
956
sub FindDuplicateAuthority {
957
    my ($record, $authtypecode) = @_;
958
959
    return unless $record;
960
961
    my $opts = C4::Context->preference('FindDuplicateOptions');
962
    return unless $opts;
900
963
901
    my ($record,$authtypecode)=@_;
902
#    warn "IN for ".$record->as_formatted;
903
    my $dbh = C4::Context->dbh;
964
    my $dbh = C4::Context->dbh;
904
#    warn "".$record->as_formatted;
965
    my $sth = $dbh->prepare("
905
    my $sth = $dbh->prepare("select auth_tag_to_report from auth_types where authtypecode=?");
966
        SELECT auth_tag_to_report FROM auth_types WHERE authtypecode = ?
967
    ");
906
    $sth->execute($authtypecode);
968
    $sth->execute($authtypecode);
907
    my ($auth_tag_to_report) = $sth->fetchrow;
969
    my ($auth_tag_to_report) = $sth->fetchrow;
908
    $sth->finish;
970
    $sth->finish;
909
#     warn "record :".$record->as_formatted."  auth_tag_to_report :$auth_tag_to_report";
971
910
    # build a request for SearchAuthorities
972
    my $authorityfield = $record->field($auth_tag_to_report);
911
    my $query='at='.$authtypecode.' ';
973
    return unless $authorityfield;
912
    my $filtervalues=qr([\001-\040\!\'\"\`\#\$\%\&\*\+,\-\./:;<=>\?\@\(\)\{\[\]\}_\|\~]);
974
913
    if ($record->field($auth_tag_to_report)) {
975
    my @tries;
914
      foreach ($record->field($auth_tag_to_report)->subfields()) {
976
    $opts =~ s/ //g;
915
        $_->[1]=~s/$filtervalues/ /g; $query.= " and he,wrdl=\"".$_->[1]."\"" if ($_->[0]=~/[A-z]/);
977
    foreach my $try (split /\|/, $opts) {
916
      }
978
        my ($index, $matchcheck) = split m#/#, $try;
979
        my ($field, @subfields);
980
        if ($matchcheck and length($matchcheck) > 3) {
981
            $field = substr $matchcheck, 0, 3;
982
            @subfields = split(//, substr($matchcheck, 3));
983
        }
984
        push @tries, {
985
            index => $index,
986
            field => $field,
987
            subfields => \@subfields,
988
        };
917
    }
989
    }
918
    my ($error, $results, $total_hits) = C4::Search::SimpleSearch( $query, 0, 1, [ "authorityserver" ] );
990
919
    # there is at least 1 result => return the 1st one
991
    my $duplicaterecord;
920
    if (!defined $error && @{$results} ) {
992
    foreach my $try (@tries) {
921
      my $marcrecord = MARC::File::USMARC::decode($results->[0]);
993
        $duplicaterecord = _find_duplicate_authority_try($try, $authorityfield,
922
      return $marcrecord->field('001')->data,BuildSummary($marcrecord,$marcrecord->field('001')->data,$authtypecode);
994
            $authtypecode);
995
        last if $duplicaterecord;
923
    }
996
    }
997
998
    if ($duplicaterecord) {
999
        my $authid = $duplicaterecord->field('001')->data;
1000
        return $authid, BuildSummary($duplicaterecord, $authid, $authtypecode);
1001
    }
1002
924
    # no result, returns nothing
1003
    # no result, returns nothing
925
    return;
1004
    return;
926
}
1005
}
(-)a/installer/data/mysql/sysprefs.sql (+2 lines)
Lines 386-388 INSERT INTO systempreferences (variable,value,explanation,type) VALUES('OPACdidy Link Here
386
INSERT INTO systempreferences (variable,value,explanation,type) VALUES('INTRAdidyoumean',NULL,'Did you mean? configuration for the Intranet. Do not change, as this is controlled by /cgi-bin/koha/admin/didyoumean.pl.','Free');
386
INSERT INTO systempreferences (variable,value,explanation,type) VALUES('INTRAdidyoumean',NULL,'Did you mean? configuration for the Intranet. Do not change, as this is controlled by /cgi-bin/koha/admin/didyoumean.pl.','Free');
387
INSERT INTO systempreferences (variable, value, options, explanation, type) VALUES ('BlockReturnOfWithdrawnItems', '1', '0', 'If enabled, items that are marked as withdrawn cannot be returned.', 'YesNo');
387
INSERT INTO systempreferences (variable, value, options, explanation, type) VALUES ('BlockReturnOfWithdrawnItems', '1', '0', 'If enabled, items that are marked as withdrawn cannot be returned.', 'YesNo');
388
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('HoldsToPullStartDate','2','Set the default start date for the Holds to pull list to this many days ago',NULL,'Integer');
388
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('HoldsToPullStartDate','2','Set the default start date for the Holds to pull list to this many days ago',NULL,'Integer');
389
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('FindDuplicateOptions','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');
390
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('FindDuplicateMaxResults','10','Maximum number of results fetched when searching a duplicate',NULL,'Free');
(-)a/installer/data/mysql/updatedatabase.pl (+14 lines)
Lines 6020-6025 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
6020
   SetVersion ($DBversion);
6020
   SetVersion ($DBversion);
6021
}
6021
}
6022
6022
6023
$DBversion = "XXX";
6024
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
6025
    $dbh->do(qq{
6026
        INSERT INTO systempreferences (variable, value, explanation, options, type)
6027
        VALUES ('FindDuplicateOptions', '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');
6028
    });
6029
    $dbh->do(qq{
6030
        INSERT INTO systempreferences (variable, value, explanation, options, type)
6031
        VALUES ('FindDuplicateMaxResults', '10', 'Maximum number of results fetched when searching a duplicate', NULL, 'Integer');
6032
    });
6033
    print "Upgrade to $DBversion done (Added system preference FindDuplicateOptions)\n";
6034
    SetVersion($DBversion);
6035
}
6036
6023
=head1 FUNCTIONS
6037
=head1 FUNCTIONS
6024
6038
6025
=head2 TableExists($table)
6039
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref (-1 / +16 lines)
Lines 43-48 Authorities: Link Here
43
                  yes: Use
43
                  yes: Use
44
                  no: "Don't use"
44
                  no: "Don't use"
45
            - authority record numbers instead of text strings for searches from subject tracings.
45
            - authority record numbers instead of text strings for searches from subject tracings.
46
        -
47
            - pref: FindDuplicateOptions
48
              class: long
49
            - '<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 omitted, the first result is returned as duplicate)'
50
            - '<br />Examples:'
51
            - '<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).'
52
            - '<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.'
53
            - '<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.'
54
            - '<br />Notes:'
55
            - '<br />- only authorities of the same type are returned by the search'
56
            - '<br />- if compared subfields are repeatable, only the first of each field is checked'
57
        -
58
            - 'Maximum number of results fetched when searching a duplicate:'
59
            - pref: FindDuplicateMaxResults
60
              class: integer
61
            - "It's only used when FindDuplicateOptions contains fields and subfields to check against (default: 10)"
46
    Linker:
62
    Linker:
47
        -
63
        -
48
            - Use the
64
            - Use the
49
- 

Return to bug 8994