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

(-)a/C4/Biblio.pm (-4 / +16 lines)
Lines 106-111 use Koha::SearchEngine; Link Here
106
use Koha::SearchEngine::Indexer;
106
use Koha::SearchEngine::Indexer;
107
use Koha::Libraries;
107
use Koha::Libraries;
108
use Koha::Util::MARC;
108
use Koha::Util::MARC;
109
use C4::Linker::Default;
109
110
110
use vars qw($debug $cgi_debug);
111
use vars qw($debug $cgi_debug);
111
112
Lines 525-531 sub BiblioAutoLink { Link Here
525
526
526
=head2 LinkBibHeadingsToAuthorities
527
=head2 LinkBibHeadingsToAuthorities
527
528
528
  my $num_headings_changed, %results = LinkBibHeadingsToAuthorities($linker, $marc, $frameworkcode, [$allowrelink, $tagtolink,  $verbose]);
529
  my $num_headings_changed, %results = LinkBibHeadingsToAuthorities($linker, $marc, $frameworkcode, [$allowrelink, $tagtolink, $dont_auto_create, $verbose]);
529
530
530
Links bib headings to authority records by checking
531
Links bib headings to authority records by checking
531
each authority-controlled field in the C<MARC::Record>
532
each authority-controlled field in the C<MARC::Record>
Lines 549-555 sub LinkBibHeadingsToAuthorities { Link Here
549
    my $allowrelink = shift;
550
    my $allowrelink = shift;
550
    my $tagtolink     = shift;
551
    my $tagtolink     = shift;
551
    my $verbose = shift;
552
    my $verbose = shift;
553
    my $dont_auto_create = shift;
552
    my %results;
554
    my %results;
555
    my $linker_default = C4::Linker::Default->new();
553
    if (!$bib) {
556
    if (!$bib) {
554
        carp 'LinkBibHeadingsToAuthorities called on undefined bib record';
557
        carp 'LinkBibHeadingsToAuthorities called on undefined bib record';
555
        return ( 0, {});
558
        return ( 0, {});
Lines 576-582 sub LinkBibHeadingsToAuthorities { Link Here
576
            next;
579
            next;
577
        }
580
        }
578
581
579
        my ( $authid, $fuzzy, $match_count ) = $linker->get_link($heading);
582
        my ( $authid, $fuzzy, $match_count, $status ) = $linker->get_link($heading);
583
        if ( defined $status ) {
584
            if ($status eq 'NO_CONNECTION' or $status eq 'SERVER_NOT_FOUND') {
585
                return 0, { error => $status };
586
            }
587
            elsif ($status eq 'Z3950_SEARCH_EMPTY') {
588
                ( $authid, $fuzzy, $match_count, $status ) = $linker_default->get_link($heading);
589
            }
590
        }
580
        if ($authid) {
591
        if ($authid) {
581
            $results{ $fuzzy ? 'fuzzy' : 'linked' }
592
            $results{ $fuzzy ? 'fuzzy' : 'linked' }
582
              ->{ $heading->display_form() }++;
593
              ->{ $heading->display_form() }++;
Lines 588-594 sub LinkBibHeadingsToAuthorities { Link Here
588
            $field->delete_subfield( code => '9' ) if defined $current_link;
599
            $field->delete_subfield( code => '9' ) if defined $current_link;
589
            $field->add_subfields( '9', $authid );
600
            $field->add_subfields( '9', $authid );
590
            $num_headings_changed++;
601
            $num_headings_changed++;
591
            push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => 'LOCAL_FOUND'}) if $verbose;
602
            push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => $status || 'LOCAL_FOUND'}) if $verbose;
592
        }
603
        }
593
        else {
604
        else {
594
            my $authority_type = Koha::Authority::Types->find( $heading->auth_type() );
605
            my $authority_type = Koha::Authority::Types->find( $heading->auth_type() );
Lines 598-606 sub LinkBibHeadingsToAuthorities { Link Here
598
                $results{'fuzzy'}->{ $heading->display_form() }++;
609
                $results{'fuzzy'}->{ $heading->display_form() }++;
599
                push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
610
                push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
600
            }
611
            }
601
            elsif ( C4::Context->preference('AutoCreateAuthorities') ) {
612
            elsif ( !$dont_auto_create && C4::Context->preference('AutoCreateAuthorities') ) {
602
                if ( _check_valid_auth_link( $current_link, $field ) ) {
613
                if ( _check_valid_auth_link( $current_link, $field ) ) {
603
                    $results{'linked'}->{ $heading->display_form() }++;
614
                    $results{'linked'}->{ $heading->display_form() }++;
615
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => 'UNCHANGED'}) if $verbose;
604
                }
616
                }
605
                elsif ( !$match_count ) {
617
                elsif ( !$match_count ) {
606
                    my $authority_type = Koha::Authority::Types->find( $heading->auth_type() );
618
                    my $authority_type = Koha::Authority::Types->find( $heading->auth_type() );
(-)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 (+315 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
29
use base qw(C4::Linker);
30
31
32
sub get_link {
33
    my $self        = shift;
34
    my $heading     = shift;
35
    my $behavior    = shift || 'default';
36
    my $search_form = $heading->search_form();
37
    my $authid;
38
    my $fuzzy = 0;
39
    my $match_count = 0;
40
    my $status = '';
41
42
    if ( $self->{'cache'}->{$search_form}->{'cached'} ) {
43
        $authid = $self->{'cache'}->{$search_form}->{'authid'};
44
        $fuzzy  = $self->{'cache'}->{$search_form}->{'fuzzy'};
45
    }else {
46
        # Look for matching authorities on the Z39.50 server
47
        unless($self->{'local_first'}) {
48
            ($authid, undef, $status) = $self->getZ3950Authority($heading);
49
            if($status eq 'Z3950_SEARCH_ERROR' or
50
               $status eq 'Z3950_QUERY_ERROR' or
51
               $status eq 'NO_CONNECTION' or
52
               $status eq 'SERVER_NOT_FOUND') {
53
                return $authid, $fuzzy, 0, $status;
54
            }
55
        }
56
        if(!$authid) {
57
            # look for matching authorities
58
            my $authorities = $heading->authorities(1);    # $skipmetadata = true
59
            $match_count = scalar @$authorities;
60
61
            if ( $behavior eq 'default' && $#{$authorities} >= 0 ) {
62
                $authid = $authorities->[0]->{'authid'};
63
            }elsif ( $behavior eq 'first' && $#{$authorities} >= 0 ) {
64
                $authid = $authorities->[0]->{'authid'};
65
                $fuzzy  = $#{$authorities} > 0;
66
            }
67
            elsif ( $behavior eq 'last' && $#{$authorities} >= 0 ) {
68
                $authid = $authorities->[ $#{$authorities} ]->{'authid'};
69
                $fuzzy  = $#{$authorities} > 0;
70
            }
71
72
            if ( !defined $authid && $self->{'broader_headings'} ) {
73
                my $field     = $heading->field();
74
                my @subfields = $field->subfields();
75
                if ( scalar @subfields > 1 ) {
76
                    pop @subfields;
77
                    $field->replace_with(
78
                        MARC::Field->new(
79
                            $field->tag,
80
                            $field->indicator(1),
81
                            $field->indicator(2),
82
                            map { $_[0] => $_[1] } @subfields
83
                        )
84
                    );
85
                    ( $authid, $fuzzy ) =
86
                      $self->get_link( C4::Heading->new_from_bib_field($field),
87
                        $behavior );
88
                }
89
            }
90
        }
91
        if($self->{'local_first'} && !$authid) {
92
            ($authid, undef, $status) = $self->getZ3950Authority($heading);
93
        }
94
95
        $self->{'cache'}->{$search_form}->{'cached'} = 1;
96
        $self->{'cache'}->{$search_form}->{'authid'} = $authid;
97
        $self->{'cache'}->{$search_form}->{'fuzzy'}  = $fuzzy;
98
    }
99
    return $self->SUPER::_handle_auth_limit($authid), $fuzzy, $match_count, $status;
100
}
101
102
sub update_cache {
103
    my $self        = shift;
104
    my $heading     = shift;
105
    my $authid      = shift;
106
    my $search_form = $heading->search_form();
107
    my $fuzzy = 0;
108
109
    $self->{'cache'}->{$search_form}->{'cached'} = 1;
110
    $self->{'cache'}->{$search_form}->{'authid'} = $authid;
111
    $self->{'cache'}->{$search_form}->{'fuzzy'}  = $fuzzy;
112
}
113
114
sub flip_heading {
115
    my $self    = shift;
116
    my $heading = shift;
117
118
    # TODO: implement
119
}
120
121
122
=head1 getZ3950Authority
123
124
  ($authid, $record, $status) = $self->getZ3950Authority($heading);
125
126
  Do a Z39.50 search for the heading using the $conn ZOOM::Connection object and the $heading Heading.
127
  The column origincode is used to check for duplicates.
128
  FIXME: Use thesaurus in search? As of Koha 3.8, the community stopped using them.
129
130
  RETURNS :
131
  $authid = the ID of the local copy of the authority record that was found. undef if nothing was found.
132
  $record = the MARC record of the found authority.
133
  $status = A string with additional informations on the search status (Z3950_CREATED, Z3950_UPDATED, Z3950_QUERY_ERROR, Z3950_SEARCH_ERROR)
134
135
=cut
136
137
sub getZ3950Authority {
138
    my $self = shift;
139
    my $heading = shift;
140
141
    # Try to find a match on the Z39.50 server if LinkerZ3950Server is set
142
    if(C4::Context->preference('LinkerZ3950Server')) {
143
        unless($self->{'conn'}) {
144
            my $sth = C4::Context->dbh->prepare("select * from z3950servers where servername=?");
145
            $sth->execute(C4::Context->preference('LinkerZ3950Server'));
146
            my $server = $sth->fetchrow_hashref or undef;
147
            $sth->finish;
148
149
            if($server) {
150
                my $options = ZOOM::Options->new();
151
                $options->option('cclfile' => C4::Context->ModZebrations('authorityserver')->{"ccl2rpn"});
152
                $options->option('elementSetName', 'F');
153
                $options->option('async', 0);
154
                $options->option('databaseName', $server->{db});
155
                $options->option('user',         $server->{userid}  ) if $server->{userid};
156
                $options->option('password',     $server->{password}) if $server->{password};
157
                $options->option('preferredRecordSyntax', $server->{syntax});
158
                $self->{'conn'} = create ZOOM::Connection($options);
159
                eval{ $self->{'conn'}->connect( $server->{host}, $server->{port} ) };
160
                if($@) {
161
                    return (undef, undef, 'NO_CONNECTION');
162
                }}
163
            else {
164
                return (undef, undef, 'SERVER_NOT_FOUND');
165
            }
166
        }
167
    }
168
    else {
169
        return;
170
    }
171
    my $query =qq(Match-Heading,do-not-truncate,ext="$heading->{'search_form'}");
172
    my $zquery = eval{ ZOOM::Query::CCL2RPN->new($query, $self->{'conn'}) };
173
    if($@) {
174
        warn $query . "\n" . $@;
175
        return (undef, undef, 'Z3950_QUERY_ERROR');
176
    }
177
178
    # Try to send the search query to the server.
179
    my $rs = eval{ $self->{'conn'}->search($zquery) };
180
    if($@){
181
        warn $query . "\n" . $@;
182
        return (undef, undef, 'Z3950_SEARCH_EMPTY');
183
    }
184
185
    # If authorities are found, select the first valid one for addition in the local authority table.
186
    my $record;
187
    if($rs->size() != 0) {
188
        $record = MARC::Record::new_from_usmarc($rs->record(0)->raw());
189
    }else{
190
        return (undef, undef, 'Z3950_SEARCH_ERROR');
191
    }
192
    $rs->destroy();
193
    $zquery->destroy();
194
195
    # If a valid authority was found, add it in the local authority database.
196
    if($record) {
197
        my $dbh=C4::Context->dbh;
198
199
        my $authtypecode = C4::AuthoritiesMarc::GuessAuthTypeCode($record);
200
        my $authId;
201
202
        # Use the control number to prevent the creation of duplicate authorities.
203
        my $controlNumber = $record->field('970')->subfield('0');
204
        my $sthExist=$dbh->prepare("SELECT authid FROM auth_header WHERE origincode =?");
205
        $sthExist->execute($controlNumber) or die $sthExist->errstr;
206
        ($authId) = $sthExist->fetchrow;
207
        $sthExist->finish;
208
209
        #------------------------------------------------------------------------------------------
210
        # Corrections and verifications before insertion
211
        my $format;
212
        my $leader='     nz  a22     o  4500';# Leader for incomplete MARC21 record
213
214
        if (uc(C4::Context->preference('marcflavour')) eq 'UNIMARC') {
215
            $format= 'UNIMARCAUTH';
216
        }
217
        else {
218
            $format= 'MARC21';
219
        }
220
221
        if ($format eq "MARC21") {
222
            if (!$record->leader) {
223
                $record->leader($leader);
224
            }
225
            if (!$record->field('003')) {
226
                $record->insert_fields_ordered(
227
                        MARC::Field->new('003',C4::Context->preference('MARCOrgCode'))
228
                        );
229
            }
230
            my $time=POSIX::strftime("%Y%m%d%H%M%S",localtime);
231
            if (!$record->field('005')) {
232
                $record->insert_fields_ordered(
233
                        MARC::Field->new('005',$time.".0")
234
                        );
235
            }
236
            my $date=POSIX::strftime("%y%m%d",localtime);
237
            if (!$record->field('008')) {
238
                # Get a valid default value for field 008
239
                my $default_008 = C4::Context->preference('MARCAuthorityControlField008');
240
                if(!$default_008 or length($default_008)<34) {
241
                    $default_008 = '|| aca||aabn           | a|a     d';
242
            }
243
            else {
244
                    $default_008 = substr($default_008,0,34);
245
                }
246
                $record->insert_fields_ordered( MARC::Field->new('008',$date.$default_008) );
247
            }
248
            if (!$record->field('040')) {
249
                $record->insert_fields_ordered(
250
                    MARC::Field->new('040','','',
251
                        'a' => C4::Context->preference('MARCOrgCode'),
252
                        'c' => C4::Context->preference('MARCOrgCode')
253
                    )
254
                );
255
            }
256
        }
257
        if ($format eq "UNIMARCAUTH") {
258
            $record->leader("     nx  j22             ") unless ($record->leader());
259
            my $date=POSIX::strftime("%Y%m%d",localtime);
260
            if (my $string=$record->subfield('100',"a")){
261
                $string=~s/fre50/frey50/;
262
                $record->field('100')->update('a'=>$string);
263
            }
264
            elsif ($record->field('100')){
265
                $record->field('100')->update('a'=>$date."afrey50      ba0");
266
            } else {
267
                $record->append_fields(
268
                    MARC::Field->new('100',' ',' '
269
                        ,'a'=>$date."afrey50      ba0")
270
                );
271
            }
272
        }
273
        my ($auth_type_tag, $auth_type_subfield) = C4::AuthoritiesMarc::get_auth_type_location($authtypecode);
274
        if (!$authId and $format eq "MARC21") {
275
        # only need to do this fix when modifying an existing authority
276
            C4::AuthoritiesMarc::MARC21::fix_marc21_auth_type_location($record, $auth_type_tag, $auth_type_subfield);
277
        }
278
        if (my $field=$record->field($auth_type_tag)){
279
            $field->update($auth_type_subfield=>$authtypecode);
280
        }
281
        else {
282
            $record->add_fields($auth_type_tag,'','', $auth_type_subfield=>$authtypecode);
283
        }
284
        #------------------------------------------------------------------------------------------
285
        if ($authId) {
286
            my $oldRecord=C4::AuthoritiesMarc::GetAuthority($authId);
287
288
            my $sth=$dbh->prepare("UPDATE auth_header SET authtypecode=?,marc=?,marcxml=? WHERE origincode =?");
289
            eval { $sth->execute($authtypecode,$record->as_usmarc,$record->as_xml_record($format),$controlNumber) or die $sth->errstr; };
290
            $sth->finish;
291
            warn "Problem with authority $controlNumber : Cannot update" if $@;
292
            $dbh->commit unless $dbh->{AutoCommit};
293
            return if $@;
294
295
            C4::Biblio::ModZebra($authId,'linkerUpdate',"authorityserver",$oldRecord,$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
            C4::Biblio::ModZebra($id,'linkerUpdate',"authorityserver",undef,$record);
309
            return ($id, $record, 'Z3950_CREATED');
310
        }
311
    }
312
    return ;
313
}
314
315
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 303-308 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
303
('LinkerModule','Default','Default|FirstMatch|LastMatch','Chooses which linker module to use (see documentation).','Choice'),
303
('LinkerModule','Default','Default|FirstMatch|LastMatch','Chooses which linker module to use (see documentation).','Choice'),
304
('LinkerOptions','','','A pipe-separated list of options for the linker.','free'),
304
('LinkerOptions','','','A pipe-separated list of options for the linker.','free'),
305
('LinkerRelink','1',NULL,'If ON the authority linker will relink headings that have previously been linked every time it runs.','YesNo'),
305
('LinkerRelink','1',NULL,'If ON the authority linker will relink headings that have previously been linked every time it runs.','YesNo'),
306
('LinkerZ3950Server','',NULL,'Import authorities from this Z39.50 server when searching for authority links with the Z39.50 Server linker module',''),
306
('LoadSearchHistoryToTheFirstLoggedUser', '1', NULL, 'If ON, the next user will automatically get the last searches in their history', 'YesNo'),
307
('LoadSearchHistoryToTheFirstLoggedUser', '1', NULL, 'If ON, the next user will automatically get the last searches in their history', 'YesNo'),
307
('LocalCoverImages','0','1','Display local cover images on intranet details pages.','YesNo'),
308
('LocalCoverImages','0','1','Display local cover images on intranet details pages.','YesNo'),
308
('LocalHoldsPriority',  '0', NULL,  'Enables the LocalHoldsPriority feature',  'YesNo'),
309
('LocalHoldsPriority',  '0', NULL,  'Enables the LocalHoldsPriority feature',  'YesNo'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref (+5 lines)
Lines 73-78 Authorities: Link Here
73
                  Default: default
73
                  Default: default
74
                  FirstMatch: "first match"
74
                  FirstMatch: "first match"
75
                  LastMatch: "last match"
75
                  LastMatch: "last match"
76
                  Z3950Server: "Z39.50 Server"
76
            - linker module for matching headings to authority records.
77
            - linker module for matching headings to authority records.
77
        -
78
        -
78
            - "Set the following options for the authority linker:"
79
            - "Set the following options for the authority linker:"
Lines 100-102 Authorities: Link Here
100
                  yes: Do
101
                  yes: Do
101
                  no: "Don't"
102
                  no: "Don't"
102
            - automatically relink headings that have previously been linked when saving records in the cataloging module.
103
            - automatically relink headings that have previously been linked when saving records in the cataloging module.
104
        -
105
            - pref: LinkerZ3950Server
106
            - class: multi
107
            - 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 287-292 function updateHeadingLinks(links) { Link Here
287
        var message = '';
287
        var message = '';
288
        var field_class = 'no_matching_authority_field';
288
        var field_class = 'no_matching_authority_field';
289
        switch(heading.status) {
289
        switch(heading.status) {
290
            case 'Z3950_CREATED':
291
                image = '<i class="fa fa-check subfield_status matching_authority"</i> ';
292
                message = _("A matching authority record was found on the Z39.50 server and was imported locally.");
293
                field_class = 'matching_authority_field';
294
                break;
295
            case 'Z3950_UPDATED':
296
                image = '<i class="fa fa-check subfield_status matching_authority"</i> ';
297
                message = _("A matching authority record was found on the Z39.50 server and a local authority was updated.");
298
                field_class = 'matching_authority_field';
299
                break;
290
            case 'LOCAL_FOUND':
300
            case 'LOCAL_FOUND':
291
                image = '<i class="fa fa-check subfield_status matching_authority"</i> ';
301
                image = '<i class="fa fa-check subfield_status matching_authority"</i> ';
292
                message = _("A matching authority was found in the local database.");
302
                message = _("A matching authority was found in the local database.");
Lines 340-346 function AutomaticLinker() { Link Here
340
    $('#f').find('.tag').each(function() {
350
    $('#f').find('.tag').each(function() {
341
        var empty = true;
351
        var empty = true;
342
        $(this).find('.input_marceditor').each(function() {
352
        $(this).find('.input_marceditor').each(function() {
343
            if($(this).val() != '') {
353
            if(this.value != '') {
344
                empty = false;
354
                empty = false;
345
                return false;
355
                return false;
346
            }
356
            }
Lines 352-359 function AutomaticLinker() { Link Here
352
362
353
    // Get all the form values to post via AJAX
363
    // Get all the form values to post via AJAX
354
    var form_data = {};
364
    var form_data = {};
365
    var i=0;
355
    $('#f').find(':input').each(function(){
366
    $('#f').find(':input').each(function(){
356
        form_data[this.name] = $(this).val();
367
       form_data[this.name] = this.value;
357
    });
368
    });
358
    delete form_data[''];
369
    delete form_data[''];
359
370
Lines 371-376 function AutomaticLinker() { Link Here
371
                case 'UNAUTHORIZED':
382
                case 'UNAUTHORIZED':
372
                    alert(_("Error : You do not have the permissions necessary to use this functionality."));
383
                    alert(_("Error : You do not have the permissions necessary to use this functionality."));
373
                    break;
384
                    break;
385
                case 'SERVER_NOT_FOUND':
386
                    alert(_("Error : The Z39.50 server configured in the 'LinkerZ3950Server' preference was not found in the Z39.50 servers list."));
387
                    break;
388
                case 'NO_CONNECTION':
389
                    alert(_("Error : Could not connect to the Z39.50 server."));
390
                    break;
374
                case 'OK':
391
                case 'OK':
375
                    updateHeadingLinks(json.links);
392
                    updateHeadingLinks(json.links);
376
                    break;
393
                    break;
(-)a/svc/cataloguing/automatic_linker.pl (-9 / +9 lines)
Lines 30-46 print $input->header('application/json'); Link Here
30
# Check the user's permissions
30
# Check the user's permissions
31
my ( $auth_status, $auth_sessid ) =
31
my ( $auth_status, $auth_sessid ) =
32
  C4::Auth::check_cookie_auth( $input->cookie('CGISESSID'), { editauthorities => 1, editcatalogue => 1 } );
32
  C4::Auth::check_cookie_auth( $input->cookie('CGISESSID'), { editauthorities => 1, editcatalogue => 1 } );
33
if ( $auth_status ne "ok" ) {
34
    print to_json( { status => 'UNAUTHORIZED' } );
35
    exit 0;
36
}
37
33
38
# Link the biblio headings to authorities and return a json containing the status of all the links.
34
# Link the biblio headings to authorities and return a json containing the status of all the links.
39
# Example : {"status":"OK","links":[{"authid":"123","status":"LINK_CHANGED","tag":"650"}]}
35
# Example : {"status":"OK","links":[{"authid":"123","status":"LINK_CHANGED","tag":"650"}]}
40
#
36
#
41
# tag = the tag number of the field
37
# tag = the tag number of the field
42
# authid = the value of the $9 subfield for this tag
38
# authid = the value of the $9 subfield for this tag
43
# status = The status of the link (LOCAL_FOUND, NONE_FOUND, MULTIPLE_MATCH, UNCHANGED, CREATED)
39
# status = The status of the link (LOCAL_FOUND, NONE_FOUND, MULTIPLE_MATCH, UNCHANGED, CREATED, 3950_CREATED, Z3950_UPDATED)
44
40
45
my $json;
41
my $json;
46
42
Lines 51-58 my ( $headings_changed, $results ) = BiblioAutoLink ( Link Here
51
    $input->param('frameworkcode'),
47
    $input->param('frameworkcode'),
52
    1
48
    1
53
);
49
);
54
50
if(defined $results->{error}) {
55
$json->{status} = 'OK';
51
    $json->{links} = $results->{details} || '';
56
$json->{links} = $results->{details} || '';
52
    $json->{links} = $results->{details} || '';
53
}
54
else{
55
    $json->{status} = 'OK';
56
    $json->{links} = $results->{details} || '';
57
}
57
58
58
print to_json($json);
59
print to_json($json);
59
- 

Return to bug 11300