|
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 |
} |