From 91f3bbffd59f87664983b2480889d23c43243067 Mon Sep 17 00:00:00 2001 From: Andreas Roussos Date: Fri, 9 Oct 2020 13:39:52 +0200 Subject: [PATCH] Bug 26641: pass the MARC field as an argument to link_bibs_to_authorities.pl When running link_bibs_to_authorities.pl, it could be useful to have the ability to specify which MARC field the script should operate on. For example, when you have a catalog where most links are in place, and you don't want the script to process every MARC field but rather limit it to a specific MARC field (e.g. 700) because you've observed that there are many missing links for that particular MARC field. This patch provides that enhancement. Test plan: 1) Run the script as follows (preferably in a test DB): time link_bibs_to_authorities.pl -v -l --test ... and notice how long it takes to complete. 2) Apply the patch. 3) Run the script again, this time providing the MARC field to work on: time link_bibs_to_authorities.pl -v -l --test -g=700 ... and, again, notice how long it takes to complete. The 2nd run should run faster than the 1st one. Signed-off-by: David Cook --- C4/Biblio.pm | 4 ++++ misc/link_bibs_to_authorities.pl | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 6b7e78e05b..1e7a7c3b67 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -482,6 +482,7 @@ sub LinkBibHeadingsToAuthorities { my $bib = shift; my $frameworkcode = shift; my $allowrelink = shift; + my $tagtolink = shift; my %results; if (!$bib) { carp 'LinkBibHeadingsToAuthorities called on undefined bib record'; @@ -493,6 +494,9 @@ sub LinkBibHeadingsToAuthorities { $allowrelink = 1 unless defined $allowrelink; my $num_headings_changed = 0; foreach my $field ( $bib->fields() ) { + if ( defined $tagtolink ) { + next unless $field->tag() == $tagtolink ; + } my $heading = C4::Heading->new_from_field( $field, $frameworkcode ); next unless defined $heading; diff --git a/misc/link_bibs_to_authorities.pl b/misc/link_bibs_to_authorities.pl index 9044292185..41a9edb63f 100755 --- a/misc/link_bibs_to_authorities.pl +++ b/misc/link_bibs_to_authorities.pl @@ -36,6 +36,7 @@ my $want_help = 0; my $auth_limit; my $bib_limit; my $commit = 100; +my $tagtolink; my $result = GetOptions( 'v|verbose' => \$verbose, @@ -44,6 +45,7 @@ my $result = GetOptions( 'a|auth-limit=s' => \$auth_limit, 'b|bib-limit=s' => \$bib_limit, 'c|commit=i' => \$commit, + 'g|tagtolink=i' => \$tagtolink, 'h|help' => \$want_help ); @@ -77,13 +79,13 @@ my %linked_headings; my %fuzzy_headings; my $dbh = C4::Context->dbh; $dbh->{AutoCommit} = 0; -process_bibs( $linker, $bib_limit, $auth_limit, $commit ); +process_bibs( $linker, $bib_limit, $auth_limit, $commit, $tagtolink ); $dbh->commit(); exit 0; sub process_bibs { - my ( $linker, $bib_limit, $auth_limit, $commit ) = @_; + my ( $linker, $bib_limit, $auth_limit, $commit, $tagtolink ) = @_; my $bib_where = ''; my $starttime = time(); if ($bib_limit) { @@ -95,7 +97,7 @@ sub process_bibs { $sth->execute(); while ( my ($biblionumber) = $sth->fetchrow_array() ) { $num_bibs_processed++; - process_bib( $linker, $biblionumber ); + process_bib( $linker, $biblionumber, $tagtolink ); if ( not $test_only and ( $num_bibs_processed % $commit ) == 0 ) { print_progress_and_commit($num_bibs_processed); @@ -187,6 +189,7 @@ _FUZZY_HEADER_ sub process_bib { my $linker = shift; my $biblionumber = shift; + my $tagtolink = shift; my $bib = GetMarcBiblio({ biblionumber => $biblionumber }); unless ( defined $bib ) { @@ -197,9 +200,10 @@ sub process_bib { } my $frameworkcode = GetFrameworkCode($biblionumber); + my $allowrelink = C4::Context->preference("CatalogModuleRelink") || ''; my ( $headings_changed, $results ) = - LinkBibHeadingsToAuthorities( $linker, $bib, $frameworkcode ); + LinkBibHeadingsToAuthorities( $linker, $bib, $frameworkcode, $allowrelink, $tagtolink ); foreach my $key ( keys %{ $results->{'unlinked'} } ) { $unlinked_headings{$key} += $results->{'unlinked'}->{$key}; } @@ -246,6 +250,7 @@ link_bibs_to_authorities.pl link_bibs_to_authorities.pl --commit=1000 link_bibs_to_authorities.pl --auth-limit=STRING link_bibs_to_authorities.pl --bib-limit=STRING + link_bibs_to_authorities.pl -g=700 =head1 DESCRIPTION @@ -281,6 +286,10 @@ Only process those bib records that match the user-specified WHERE clause. Commit the results to the database after every N records are processed. +=item B<-g=N> + +Only process those headings found in MARC field N. + =item B<--test> Only test the authority linking and report the results; do not change the bib -- 2.11.0