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

(-)a/C4/Biblio.pm (-4 / +17 lines)
Lines 115-120 use Koha::SearchEngine; Link Here
115
use Koha::SearchEngine::Indexer;
115
use Koha::SearchEngine::Indexer;
116
use Koha::Libraries;
116
use Koha::Libraries;
117
use Koha::Util::MARC;
117
use Koha::Util::MARC;
118
use Koha::MetadataRecord;
119
use C4::Linker::Default;
118
120
119
=head1 NAME
121
=head1 NAME
120
122
Lines 618-624 sub BiblioAutoLink { Link Here
618
620
619
=head2 LinkBibHeadingsToAuthorities
621
=head2 LinkBibHeadingsToAuthorities
620
622
621
  my $num_headings_changed, %results = LinkBibHeadingsToAuthorities($linker, $marc, $frameworkcode, [$allowrelink, $tagtolink,  $verbose]);
623
  my $num_headings_changed, %results = LinkBibHeadingsToAuthorities($linker, $marc, $frameworkcode, [$allowrelink, $tagtolink, $dont_auto_create, $verbose]);
622
624
623
Links bib headings to authority records by checking
625
Links bib headings to authority records by checking
624
each authority-controlled field in the C<MARC::Record>
626
each authority-controlled field in the C<MARC::Record>
Lines 642-648 sub LinkBibHeadingsToAuthorities { Link Here
642
    my $allowrelink = shift;
644
    my $allowrelink = shift;
643
    my $tagtolink     = shift;
645
    my $tagtolink     = shift;
644
    my $verbose = shift;
646
    my $verbose = shift;
647
    my $dont_auto_create = shift;
645
    my %results;
648
    my %results;
649
    my $linker_default = C4::Linker::Default->new();
646
    if (!$bib) {
650
    if (!$bib) {
647
        carp 'LinkBibHeadingsToAuthorities called on undefined bib record';
651
        carp 'LinkBibHeadingsToAuthorities called on undefined bib record';
648
        return ( 0, {});
652
        return ( 0, {});
Lines 669-675 sub LinkBibHeadingsToAuthorities { Link Here
669
            next;
673
            next;
670
        }
674
        }
671
675
672
        my ( $authid, $fuzzy, $match_count ) = $linker->get_link($heading);
676
        my ( $authid, $fuzzy, $match_count, $status ) = $linker->get_link($heading);
677
        if ( defined $status ) {
678
            if ($status eq 'NO_CONNECTION' or $status eq 'SERVER_NOT_FOUND') {
679
                return 0, { error => $status };
680
            }
681
            elsif ($status eq 'Z3950_SEARCH_EMPTY') {
682
                ( $authid, $fuzzy, $match_count, $status ) = $linker_default->get_link($heading);
683
            }
684
        }
673
        if ($authid) {
685
        if ($authid) {
674
            $results{ $fuzzy ? 'fuzzy' : 'linked' }
686
            $results{ $fuzzy ? 'fuzzy' : 'linked' }
675
              ->{ $heading->display_form() }++;
687
              ->{ $heading->display_form() }++;
Lines 681-687 sub LinkBibHeadingsToAuthorities { Link Here
681
            $field->delete_subfield( code => '9' ) if defined $current_link;
693
            $field->delete_subfield( code => '9' ) if defined $current_link;
682
            $field->add_subfields( '9', $authid );
694
            $field->add_subfields( '9', $authid );
683
            $num_headings_changed++;
695
            $num_headings_changed++;
684
            push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => 'LOCAL_FOUND'}) if $verbose;
696
            push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => $status || 'LOCAL_FOUND'}) if $verbose;
685
        }
697
        }
686
        else {
698
        else {
687
            my $authority_type = Koha::Authority::Types->find( $heading->auth_type() );
699
            my $authority_type = Koha::Authority::Types->find( $heading->auth_type() );
Lines 691-699 sub LinkBibHeadingsToAuthorities { Link Here
691
                $results{'fuzzy'}->{ $heading->display_form() }++;
703
                $results{'fuzzy'}->{ $heading->display_form() }++;
692
                push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
704
                push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
693
            }
705
            }
694
            elsif ( C4::Context->preference('AutoCreateAuthorities') ) {
706
            elsif ( !$dont_auto_create && C4::Context->preference('AutoCreateAuthorities') ) {
695
                if ( _check_valid_auth_link( $current_link, $field ) ) {
707
                if ( _check_valid_auth_link( $current_link, $field ) ) {
696
                    $results{'linked'}->{ $heading->display_form() }++;
708
                    $results{'linked'}->{ $heading->display_form() }++;
709
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => 'UNCHANGED'}) if $verbose;
697
                } elsif ( $match_count > 1 ) {
710
                } elsif ( $match_count > 1 ) {
698
                    $results{'unlinked'}->{ $heading->display_form() }++;
711
                    $results{'unlinked'}->{ $heading->display_form() }++;
699
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => undef, status => 'MULTIPLE_MATCH', auth_type => $heading->auth_type(), tag_to_report => $authority_type->auth_tag_to_report}) if $verbose;
712
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => undef, status => 'MULTIPLE_MATCH', auth_type => $heading->auth_type(), tag_to_report => $authority_type->auth_tag_to_report}) if $verbose;
(-)a/C4/Biblio.pm.rej (+20 lines)
Line 0 Link Here
1
diff a/C4/Biblio.pm b/C4/Biblio.pm	(rejected hunks)
2
@@ -461,7 +462,7 @@ sub BiblioAutoLink {
3
4
 =head2 LinkBibHeadingsToAuthorities
5
6
-  my $num_headings_changed, %results = LinkBibHeadingsToAuthorities($linker, $marc, $frameworkcode, [$allowrelink, $verbose]);
7
+  my $num_headings_changed, %results = LinkBibHeadingsToAuthorities($linker, $marc, $frameworkcode, [$allowrelink, $verbose, $dont_auto_create]);
8
9
 Links bib headings to authority records by checking
10
 each authority-controlled field in the C<MARC::Record>
11
@@ -484,7 +485,9 @@ sub LinkBibHeadingsToAuthorities {
12
     my $frameworkcode = shift;
13
     my $allowrelink = shift;
14
     my $verbose = shift;
15
+    my $dont_auto_create = shift;
16
     my %results;
17
+    my $linker_default=C4::Linker::Default->new();
18
     if (!$bib) {
19
         carp 'LinkBibHeadingsToAuthorities called on undefined bib record';
20
         return ( 0, {});
(-)a/C4/Linker/Z3950Server.pm (+316 lines)
Line 0 Link Here
1
package C4::Linker::Z3950Server;
2
3
# Copyright 2012 Frédérick Capovilla - Libéo
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use strict;
19
use warnings;
20
use Carp;
21
use MARC::Field;
22
use MARC::Record;
23
use C4::Context;
24
use C4::Heading;
25
use ZOOM; # For Z39.50 Searches
26
use C4::AuthoritiesMarc; # For Authority addition
27
use C4::Log; # logaction
28
use Koha::SearchEngine::Indexer;
29
30
use base qw(C4::Linker);
31
32
33
sub get_link {
34
    my $self        = shift;
35
    my $heading     = shift;
36
    my $behavior    = shift || 'default';
37
    my $search_form = $heading->search_form();
38
    my $authid;
39
    my $fuzzy = 0;
40
    my $match_count = 0;
41
    my $status = '';
42
43
    if ( $self->{'cache'}->{$search_form}->{'cached'} ) {
44
        $authid = $self->{'cache'}->{$search_form}->{'authid'};
45
        $fuzzy  = $self->{'cache'}->{$search_form}->{'fuzzy'};
46
    }else {
47
        # Look for matching authorities on the Z39.50 server
48
        unless($self->{'local_first'}) {
49
            ($authid, undef, $status) = $self->getZ3950Authority($heading);
50
            if($status eq 'Z3950_SEARCH_ERROR' or
51
               $status eq 'Z3950_QUERY_ERROR' or
52
               $status eq 'NO_CONNECTION' or
53
               $status eq 'SERVER_NOT_FOUND') {
54
                return $authid, $fuzzy, 0, $status;
55
            }
56
        }
57
        if(!$authid) {
58
            # look for matching authorities
59
            my $authorities = $heading->authorities(1);    # $skipmetadata = true
60
            $match_count = scalar @$authorities;
61
62
            if ( $behavior eq 'default' && $#{$authorities} >= 0 ) {
63
                $authid = $authorities->[0]->{'authid'};
64
            }elsif ( $behavior eq 'first' && $#{$authorities} >= 0 ) {
65
                $authid = $authorities->[0]->{'authid'};
66
                $fuzzy  = $#{$authorities} > 0;
67
            }
68
            elsif ( $behavior eq 'last' && $#{$authorities} >= 0 ) {
69
                $authid = $authorities->[ $#{$authorities} ]->{'authid'};
70
                $fuzzy  = $#{$authorities} > 0;
71
            }
72
73
            if ( !defined $authid && $self->{'broader_headings'} ) {
74
                my $field     = $heading->field();
75
                my @subfields = $field->subfields();
76
                if ( scalar @subfields > 1 ) {
77
                    pop @subfields;
78
                    $field->replace_with(
79
                        MARC::Field->new(
80
                            $field->tag,
81
                            $field->indicator(1),
82
                            $field->indicator(2),
83
                            map { $_[0] => $_[1] } @subfields
84
                        )
85
                    );
86
                    ( $authid, $fuzzy ) =
87
                      $self->get_link( C4::Heading->new_from_bib_field($field),
88
                        $behavior );
89
                }
90
            }
91
        }
92
        if($self->{'local_first'} && !$authid) {
93
            ($authid, undef, $status) = $self->getZ3950Authority($heading);
94
        }
95
96
        $self->{'cache'}->{$search_form}->{'cached'} = 1;
97
        $self->{'cache'}->{$search_form}->{'authid'} = $authid;
98
        $self->{'cache'}->{$search_form}->{'fuzzy'}  = $fuzzy;
99
    }
100
    return $self->SUPER::_handle_auth_limit($authid), $fuzzy, $match_count, $status;
101
}
102
103
sub update_cache {
104
    my $self        = shift;
105
    my $heading     = shift;
106
    my $authid      = shift;
107
    my $search_form = $heading->search_form();
108
    my $fuzzy = 0;
109
110
    $self->{'cache'}->{$search_form}->{'cached'} = 1;
111
    $self->{'cache'}->{$search_form}->{'authid'} = $authid;
112
    $self->{'cache'}->{$search_form}->{'fuzzy'}  = $fuzzy;
113
}
114
115
sub flip_heading {
116
    my $self    = shift;
117
    my $heading = shift;
118
119
    # TODO: implement
120
}
121
122
123
=head1 getZ3950Authority
124
125
  ($authid, $record, $status) = $self->getZ3950Authority($heading);
126
127
  Do a Z39.50 search for the heading using the $conn ZOOM::Connection object and the $heading Heading.
128
  The column origincode is used to check for duplicates.
129
  FIXME: Use thesaurus in search? As of Koha 3.8, the community stopped using them.
130
131
  RETURNS :
132
  $authid = the ID of the local copy of the authority record that was found. undef if nothing was found.
133
  $record = the MARC record of the found authority.
134
  $status = A string with additional informations on the search status (Z3950_CREATED, Z3950_UPDATED, Z3950_QUERY_ERROR, Z3950_SEARCH_ERROR)
135
136
=cut
137
138
sub getZ3950Authority {
139
    my $self = shift;
140
    my $heading = shift;
141
142
    # Try to find a match on the Z39.50 server if LinkerZ3950Server is set
143
    if(C4::Context->preference('LinkerZ3950Server')) {
144
        unless($self->{'conn'}) {
145
            my $sth = C4::Context->dbh->prepare("select * from z3950servers where servername=?");
146
            $sth->execute(C4::Context->preference('LinkerZ3950Server'));
147
            my $server = $sth->fetchrow_hashref or undef;
148
            $sth->finish;
149
150
            if($server) {
151
                my $options = ZOOM::Options->new();
152
                $options->option('cclfile' => C4::Context->new()->{"serverinfo"}->{"authorityserver"}->{"ccl2rpn"});
153
                $options->option('elementSetName', 'F');
154
                $options->option('async', 0);
155
                $options->option('databaseName', $server->{db});
156
                $options->option('user',         $server->{userid}  ) if $server->{userid};
157
                $options->option('password',     $server->{password}) if $server->{password};
158
                $options->option('preferredRecordSyntax', $server->{syntax});
159
                $self->{'conn'} = create ZOOM::Connection($options);
160
                eval{ $self->{'conn'}->connect( $server->{host}, $server->{port} ) };
161
                if($@) {
162
                    return (undef, undef, 'NO_CONNECTION');
163
                }}
164
            else {
165
                return (undef, undef, 'SERVER_NOT_FOUND');
166
            }
167
        }
168
    }
169
    else {
170
        return;
171
    }
172
    my $query =qq(Match-Heading,do-not-truncate,ext="$heading->{'search_form'}");
173
    my $zquery = eval{ ZOOM::Query::CCL2RPN->new($query, $self->{'conn'}) };
174
    if($@) {
175
        warn $query . "\n" . $@;
176
        return (undef, undef, 'Z3950_QUERY_ERROR');
177
    }
178
179
    # Try to send the search query to the server.
180
    my $rs = eval{ $self->{'conn'}->search($zquery) };
181
    if($@){
182
        warn $query . "\n" . $@;
183
        return (undef, undef, 'Z3950_SEARCH_EMPTY');
184
    }
185
186
    # If authorities are found, select the first valid one for addition in the local authority table.
187
    my $record;
188
    if($rs->size() != 0) {
189
        $record = MARC::Record::new_from_usmarc($rs->record(0)->raw());
190
    }else{
191
        return (undef, undef, 'Z3950_SEARCH_ERROR');
192
    }
193
    $rs->destroy();
194
    $zquery->destroy();
195
196
    # If a valid authority was found, add it in the local authority database.
197
    if($record) {
198
        my $dbh=C4::Context->dbh;
199
200
        my $authtypecode = C4::AuthoritiesMarc::GuessAuthTypeCode($record);
201
        my $authId;
202
203
        # Use the control number to prevent the creation of duplicate authorities.
204
        my $controlNumber = $record->field('970')->subfield('0');
205
        my $sthExist=$dbh->prepare("SELECT authid FROM auth_header WHERE origincode =?");
206
        $sthExist->execute($controlNumber) or die $sthExist->errstr;
207
        ($authId) = $sthExist->fetchrow;
208
        $sthExist->finish;
209
210
        #------------------------------------------------------------------------------------------
211
        # Corrections and verifications before insertion
212
        my $format;
213
        my $leader='     nz  a22     o  4500';# Leader for incomplete MARC21 record
214
215
        if (uc(C4::Context->preference('marcflavour')) eq 'UNIMARC') {
216
            $format= 'UNIMARCAUTH';
217
        }
218
        else {
219
            $format= 'MARC21';
220
        }
221
222
        if ($format eq "MARC21") {
223
            if (!$record->leader) {
224
                $record->leader($leader);
225
            }
226
            if (!$record->field('003')) {
227
                $record->insert_fields_ordered(
228
                        MARC::Field->new('003',C4::Context->preference('MARCOrgCode'))
229
                        );
230
            }
231
            my $time=POSIX::strftime("%Y%m%d%H%M%S",localtime);
232
            if (!$record->field('005')) {
233
                $record->insert_fields_ordered(
234
                        MARC::Field->new('005',$time.".0")
235
                        );
236
            }
237
            my $date=POSIX::strftime("%y%m%d",localtime);
238
            if (!$record->field('008')) {
239
                # Get a valid default value for field 008
240
                my $default_008 = C4::Context->preference('MARCAuthorityControlField008');
241
                if(!$default_008 or length($default_008)<34) {
242
                    $default_008 = '|| aca||aabn           | a|a     d';
243
            }
244
            else {
245
                    $default_008 = substr($default_008,0,34);
246
                }
247
                $record->insert_fields_ordered( MARC::Field->new('008',$date.$default_008) );
248
            }
249
            if (!$record->field('040')) {
250
                $record->insert_fields_ordered(
251
                    MARC::Field->new('040','','',
252
                        'a' => C4::Context->preference('MARCOrgCode'),
253
                        'c' => C4::Context->preference('MARCOrgCode')
254
                    )
255
                );
256
            }
257
        }
258
        if ($format eq "UNIMARCAUTH") {
259
            $record->leader("     nx  j22             ") unless ($record->leader());
260
            my $date=POSIX::strftime("%Y%m%d",localtime);
261
            if (my $string=$record->subfield('100',"a")){
262
                $string=~s/fre50/frey50/;
263
                $record->field('100')->update('a'=>$string);
264
            }
265
            elsif ($record->field('100')){
266
                $record->field('100')->update('a'=>$date."afrey50      ba0");
267
            } else {
268
                $record->append_fields(
269
                    MARC::Field->new('100',' ',' '
270
                        ,'a'=>$date."afrey50      ba0")
271
                );
272
            }
273
        }
274
        my ($auth_type_tag, $auth_type_subfield) = C4::AuthoritiesMarc::get_auth_type_location($authtypecode);
275
        if (!$authId and $format eq "MARC21") {
276
        # only need to do this fix when modifying an existing authority
277
            C4::AuthoritiesMarc::MARC21::fix_marc21_auth_type_location($record, $auth_type_tag, $auth_type_subfield);
278
        }
279
        if (my $field=$record->field($auth_type_tag)){
280
            $field->update($auth_type_subfield=>$authtypecode);
281
        }
282
        else {
283
            $record->add_fields($auth_type_tag,'','', $auth_type_subfield=>$authtypecode);
284
        }
285
        #------------------------------------------------------------------------------------------
286
        if ($authId) {
287
            my $sth=$dbh->prepare("UPDATE auth_header SET authtypecode=?,marc=?,marcxml=? WHERE origincode =?");
288
            eval { $sth->execute($authtypecode,$record->as_usmarc,$record->as_xml_record($format),$controlNumber) or die $sth->errstr; };
289
            $sth->finish;
290
            warn "Problem with authority $controlNumber : Cannot update" if $@;
291
            $dbh->commit unless $dbh->{AutoCommit};
292
            return if $@;
293
294
            my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::AUTHORITIES_INDEX });
295
            $indexer->index_records($authId,'specialUpdate',"authorityserver",$record);
296
            return ($authId, $record, 'Z3950_UPDATED');
297
        }
298
        else {
299
            my $sth=$dbh->prepare("INSERT INTO auth_header (datecreated,authtypecode,marc,marcxml,origincode) VALUES (NOW(),?,?,?,?)");
300
            eval { $sth->execute($authtypecode,$record->as_usmarc,$record->as_xml_record($format),$controlNumber) or die $sth->errstr; };
301
            $sth->finish;
302
            warn "Problem with authority $controlNumber : Cannot insert" if $@;
303
            my $id = $dbh->{'mysql_insertid'};
304
            $dbh->commit unless $dbh->{AutoCommit};
305
            return if $@;
306
307
            logaction( "AUTHORITIES", "ADD", $id, "authority" ) if C4::Context->preference("AuthoritiesLog");
308
            my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::AUTHORITIES_INDEX });
309
            $indexer->index_records($id,'specialUpdate',"authorityserver",$record);
310
            return ($id, $record, 'Z3950_CREATED');
311
        }
312
    }
313
    return ;
314
}
315
316
1;
(-)a/installer/data/mysql/atomicupdate/Bug11300_LinkerZ3950Server_syspef.sql (+9 lines)
Line 0 Link Here
1
$DBversion = 'XXX';
2
if ( CheckVersion( $DBversion ) ) {
3
    $dbh->do(q{
4
        INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`)
5
        VALUES ('LinkerZ3950Server', '', NULL, 'Import authorities from this Z39.50 server when searching for authority links with the Z39.50 Server linker module', 'free')
6
    ­});
7
8
    NewVersion( $DBversion, 12446, "Add new system preference LinkerZ3950Server");
9
}
(-)a/installer/data/mysql/mandatory/sysprefs.sql (+1 lines)
Lines 366-371 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
366
('LinkerModule','Default','Default|FirstMatch|LastMatch','Chooses which linker module to use (see documentation).','Choice'),
366
('LinkerModule','Default','Default|FirstMatch|LastMatch','Chooses which linker module to use (see documentation).','Choice'),
367
('LinkerOptions','','','A pipe-separated list of options for the linker.','free'),
367
('LinkerOptions','','','A pipe-separated list of options for the linker.','free'),
368
('LinkerRelink','1',NULL,'If ON the authority linker will relink headings that have previously been linked every time it runs.','YesNo'),
368
('LinkerRelink','1',NULL,'If ON the authority linker will relink headings that have previously been linked every time it runs.','YesNo'),
369
('LinkerZ3950Server','',NULL,'Import authorities from this Z39.50 server when searching for authority links with the Z39.50 Server linker module',''),
369
('ListOwnerDesignated', NULL, NULL, 'Designated list owner at patron deletion', 'Free'),
370
('ListOwnerDesignated', NULL, NULL, 'Designated list owner at patron deletion', 'Free'),
370
('ListOwnershipUponPatronDeletion', 'delete', 'delete|transfer', 'Defines the action on their public or shared lists when patron is deleted', 'Choice'),
371
('ListOwnershipUponPatronDeletion', 'delete', 'delete|transfer', 'Defines the action on their public or shared lists when patron is deleted', 'Choice'),
371
('LoadCheckoutsTableDelay','0','','Delay before auto-loading checkouts table on checkouts screen','Integer'),
372
('LoadCheckoutsTableDelay','0','','Delay before auto-loading checkouts table on checkouts screen','Integer'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref (+5 lines)
Lines 105-110 Authorities: Link Here
105
                  Default: default
105
                  Default: default
106
                  FirstMatch: "first match"
106
                  FirstMatch: "first match"
107
                  LastMatch: "last match"
107
                  LastMatch: "last match"
108
                  Z3950Server: "Z39.50 Server"
108
            - linker module for matching headings to authority records.
109
            - linker module for matching headings to authority records.
109
        -
110
        -
110
            - "Set the following options for the authority linker:"
111
            - "Set the following options for the authority linker:"
Lines 146-148 Authorities: Link Here
146
                  1: Do
147
                  1: Do
147
                  0: "Don't"
148
                  0: "Don't"
148
            - compare the source for 6XX headings to the thesaurus source for authority records when linking. Enabling this preference may require a reindex, and may generate new authority records if AutoCreateAuthorities is enabled.
149
            - compare the source for 6XX headings to the thesaurus source for authority records when linking. Enabling this preference may require a reindex, and may generate new authority records if AutoCreateAuthorities is enabled.
150
        -
151
            - pref: LinkerZ3950Server
152
            - class: multi
153
            - Import authorities from this Z39.50 server when searching for authority links with the Z39.50 Server linker module :
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt (-2 / +19 lines)
Lines 363-368 function updateHeadingLinks(links) { Link Here
363
        var message = '';
363
        var message = '';
364
        var field_class = 'no_matching_authority_field';
364
        var field_class = 'no_matching_authority_field';
365
        switch(heading.status) {
365
        switch(heading.status) {
366
            case 'Z3950_CREATED':
367
                image = '<i class="fa fa-check subfield_status matching_authority"</i> ';
368
                message = _("A matching authority record was found on the Z39.50 server and was imported locally.");
369
                field_class = 'matching_authority_field';
370
                break;
371
            case 'Z3950_UPDATED':
372
                image = '<i class="fa fa-check subfield_status matching_authority"</i> ';
373
                message = _("A matching authority record was found on the Z39.50 server and a local authority was updated.");
374
                field_class = 'matching_authority_field';
375
                break;
366
            case 'LOCAL_FOUND':
376
            case 'LOCAL_FOUND':
367
                image = '<i class="fa fa-check subfield_status matching_authority"</i> ';
377
                image = '<i class="fa fa-check subfield_status matching_authority"</i> ';
368
                message = _("A matching authority was found in the local database.");
378
                message = _("A matching authority was found in the local database.");
Lines 416-422 function AutomaticLinker() { Link Here
416
    $('#f').find('.tag').each(function() {
426
    $('#f').find('.tag').each(function() {
417
        var empty = true;
427
        var empty = true;
418
        $(this).find('.input_marceditor').each(function() {
428
        $(this).find('.input_marceditor').each(function() {
419
            if($(this).val() != '') {
429
            if(this.value != '') {
420
                empty = false;
430
                empty = false;
421
                return false;
431
                return false;
422
            }
432
            }
Lines 428-435 function AutomaticLinker() { Link Here
428
438
429
    // Get all the form values to post via AJAX
439
    // Get all the form values to post via AJAX
430
    var form_data = {};
440
    var form_data = {};
441
    var i=0;
431
    $('#f').find(':input').each(function(){
442
    $('#f').find(':input').each(function(){
432
        form_data[this.name] = $(this).val();
443
       form_data[this.name] = this.value;
433
    });
444
    });
434
    delete form_data[''];
445
    delete form_data[''];
435
446
Lines 447-452 function AutomaticLinker() { Link Here
447
                case 'UNAUTHORIZED':
458
                case 'UNAUTHORIZED':
448
                    alert(_("Error : You do not have the permissions necessary to use this functionality."));
459
                    alert(_("Error : You do not have the permissions necessary to use this functionality."));
449
                    break;
460
                    break;
461
                case 'SERVER_NOT_FOUND':
462
                    alert(_("Error : The Z39.50 server configured in the 'LinkerZ3950Server' preference was not found in the Z39.50 servers list."));
463
                    break;
464
                case 'NO_CONNECTION':
465
                    alert(_("Error : Could not connect to the Z39.50 server."));
466
                    break;
450
                case 'OK':
467
                case 'OK':
451
                    updateHeadingLinks(json.links);
468
                    updateHeadingLinks(json.links);
452
                    break;
469
                    break;
(-)a/svc/cataloguing/automatic_linker.pl (-9 / +9 lines)
Lines 33-49 my ( $auth_status ) = Link Here
33
    editauthorities => 1,
33
    editauthorities => 1,
34
    editcatalogue => 'edit_catalogue'
34
    editcatalogue => 'edit_catalogue'
35
  });
35
  });
36
if ( $auth_status ne "ok" ) {
37
    print to_json( { status => 'UNAUTHORIZED' } );
38
    exit 0;
39
}
40
36
41
# Link the biblio headings to authorities and return a json containing the status of all the links.
37
# Link the biblio headings to authorities and return a json containing the status of all the links.
42
# Example : {"status":"OK","links":[{"authid":"123","status":"LINK_CHANGED","tag":"650"}]}
38
# Example : {"status":"OK","links":[{"authid":"123","status":"LINK_CHANGED","tag":"650"}]}
43
#
39
#
44
# tag = the tag number of the field
40
# tag = the tag number of the field
45
# authid = the value of the $9 subfield for this tag
41
# authid = the value of the $9 subfield for this tag
46
# status = The status of the link (LOCAL_FOUND, NONE_FOUND, MULTIPLE_MATCH, UNCHANGED, CREATED)
42
# status = The status of the link (LOCAL_FOUND, NONE_FOUND, MULTIPLE_MATCH, UNCHANGED, CREATED, 3950_CREATED, Z3950_UPDATED)
47
43
48
my $json;
44
my $json;
49
45
Lines 54-61 my ( $headings_changed, $results ) = BiblioAutoLink ( Link Here
54
    scalar $input->param('frameworkcode'),
50
    scalar $input->param('frameworkcode'),
55
    1
51
    1
56
);
52
);
57
53
if(defined $results->{error}) {
58
$json->{status} = 'OK';
54
    $json->{links} = $results->{details} || '';
59
$json->{links} = $results->{details} || '';
55
    $json->{links} = $results->{details} || '';
56
}
57
else{
58
    $json->{status} = 'OK';
59
    $json->{links} = $results->{details} || '';
60
}
60
61
61
print to_json($json);
62
print to_json($json);
62
- 

Return to bug 11300