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

(-)a/C4/Biblio.pm (-7 / +10 lines)
Lines 487-499 sub BiblioAutoLink { Link Here
487
    my $linker = $linker_module->new(
487
    my $linker = $linker_module->new(
488
        { 'options' => C4::Context->preference("LinkerOptions") } );
488
        { 'options' => C4::Context->preference("LinkerOptions") } );
489
    my ( $headings_changed, undef ) =
489
    my ( $headings_changed, undef ) =
490
      LinkBibHeadingsToAuthorities( $linker, $record, $frameworkcode );
490
      LinkBibHeadingsToAuthorities( $linker, $record, $frameworkcode, C4::Context->preference("CatalogModuleRelink") || '' );
491
    # By default we probably don't want to relink things when cataloging
491
    return $headings_changed;
492
    return $headings_changed;
492
}
493
}
493
494
494
=head2 LinkBibHeadingsToAuthorities
495
=head2 LinkBibHeadingsToAuthorities
495
496
496
  my $num_headings_changed, %results = LinkBibHeadingsToAuthorities($linker, $marc, $frameworkcode);
497
  my $num_headings_changed, %results = LinkBibHeadingsToAuthorities($linker, $marc, $frameworkcode, [$allowrelink]);
497
498
498
Links bib headings to authority records by checking
499
Links bib headings to authority records by checking
499
each authority-controlled field in the C<MARC::Record>
500
each authority-controlled field in the C<MARC::Record>
Lines 501-509 object C<$marc>, looking for a matching authority record, Link Here
501
and setting the linking subfield $9 to the ID of that
502
and setting the linking subfield $9 to the ID of that
502
authority record.  
503
authority record.  
503
504
504
If no matching authority exists, or if multiple
505
If $allowrelink is false, existing authids will never be
505
authorities match, no $9 will be added, and any 
506
replaced, regardless of the values of LinkerKeepStale and
506
existing one inthe field will be deleted.
507
LinkerRelink.
507
508
508
Returns the number of heading links changed in the
509
Returns the number of heading links changed in the
509
MARC record.
510
MARC record.
Lines 514-522 sub LinkBibHeadingsToAuthorities { Link Here
514
    my $linker        = shift;
515
    my $linker        = shift;
515
    my $bib           = shift;
516
    my $bib           = shift;
516
    my $frameworkcode = shift;
517
    my $frameworkcode = shift;
518
    my $allowrelink = shift;
517
    my %results;
519
    my %results;
518
    require C4::AuthoritiesMarc;
520
    require C4::AuthoritiesMarc;
519
521
522
    $allowrelink = 1 unless defined $allowrelink;
520
    my $num_headings_changed = 0;
523
    my $num_headings_changed = 0;
521
    foreach my $field ( $bib->fields() ) {
524
    foreach my $field ( $bib->fields() ) {
522
        my $heading = C4::Heading->new_from_bib_field( $field, $frameworkcode );
525
        my $heading = C4::Heading->new_from_bib_field( $field, $frameworkcode );
Lines 525-531 sub LinkBibHeadingsToAuthorities { Link Here
525
        # check existing $9
528
        # check existing $9
526
        my $current_link = $field->subfield('9');
529
        my $current_link = $field->subfield('9');
527
530
528
        if ( defined $current_link && !C4::Context->preference('LinkerRelink') )
531
        if ( defined $current_link && (!$allowrelink || !C4::Context->preference('LinkerRelink')) )
529
        {
532
        {
530
            $results{'linked'}->{ $heading->display_form() }++;
533
            $results{'linked'}->{ $heading->display_form() }++;
531
            next;
534
            next;
Lines 543-549 sub LinkBibHeadingsToAuthorities { Link Here
543
        }
546
        }
544
        else {
547
        else {
545
            if ( defined $current_link
548
            if ( defined $current_link
546
                && C4::Context->preference('LinkerKeepStale') )
549
                && (!$allowrelink || C4::Context->preference('LinkerKeepStale')) )
547
            {
550
            {
548
                $results{'fuzzy'}->{ $heading->display_form() }++;
551
                $results{'fuzzy'}->{ $heading->display_form() }++;
549
            }
552
            }
(-)a/installer/data/mysql/atomicupdate/bug_7284_authority_linking_pt2 (+9 lines)
Line 0 Link Here
1
#! /usr/bin/perl
2
use strict;
3
use warnings;
4
use C4::Context;
5
my $dbh = C4::Context->dbh;
6
$dbh->do(
7
"INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('CatalogModuleRelink',0,'If OFF the linker will never replace the authids that are set in the cataloging module.',NULL,'YesNo');"
8
);
9
print "Upgrade done (Configured bug 7284, added the )\n";
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 339-341 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES(' Link Here
339
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('LinkerOptions','','A pipe-separated list of options for the linker.','','free');
339
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('LinkerOptions','','A pipe-separated list of options for the linker.','','free');
340
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('LinkerRelink',1,'If ON the authority linker will relink headings that have previously been linked every time it runs.',NULL,'YesNo');
340
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('LinkerRelink',1,'If ON the authority linker will relink headings that have previously been linked every time it runs.',NULL,'YesNo');
341
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('LinkerKeepStale',0,'If ON the authority linker will keep existing authority links for headings where it is unable to find a match.',NULL,'YesNo');
341
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('LinkerKeepStale',0,'If ON the authority linker will keep existing authority links for headings where it is unable to find a match.',NULL,'YesNo');
342
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('CatalogModuleRelink',0,'If OFF the linker will never replace the authids that are set in the cataloging module.',NULL,'YesNo');
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref (-1 / +7 lines)
Lines 65-67 Authorities: Link Here
65
                  yes: Do
65
                  yes: Do
66
                  no: "Do not"
66
                  no: "Do not"
67
            - keep existing links to authority records for headings where the linker is unable to find a match.
67
            - keep existing links to authority records for headings where the linker is unable to find a match.
68
- 
68
        -
69
            - pref: CatalogModuleRelink
70
              default: no
71
              choices:
72
                  yes: Do
73
                  no: "Do not"
74
            - automatically relink headings that have previously been linked when saving records in the cataloging module.

Return to bug 7284