From 08908b5765e941723d454591608235bd1451c8a8 Mon Sep 17 00:00:00 2001 From: David Gustafsson Date: Wed, 21 Sep 2022 17:43:32 +0200 Subject: [PATCH] Bug 29440: defer biblio autolinking until records are indexed MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Kula <148193449+mkibp@users.noreply.github.com> Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- C4/Biblio.pm | 16 +++++++++++++--- misc/migration_tools/bulkmarcimport.pl | 9 ++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 1dc0ab6b79..53b0fa5a03 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -190,9 +190,17 @@ The C<$options> argument is a hashref with additional parameters: =over 4 -=item B: used when ModBiblioMarc is handled by the caller +=item B +Used when ModBiblioMarc is handled by the caller -=item B: used when the indexing scheduling will be handled by the caller +=item B +Used when the indexing scheduling will be handled by the caller + +=item C + +Unless C is passed AddBiblio will link record headings +to authorities based on settings in the system preferences. This flag allows +us to not link records when the authority linker is saving modifications. =back @@ -204,6 +212,7 @@ sub AddBiblio { $options //= {}; my $skip_record_index = $options->{'skip_record_index'} // 0; my $defer_marc_save = $options->{defer_marc_save} // 0; + my $disable_autolink = $options->{disable_autolink} // 0; if (!$record) { carp('AddBiblio called with undefined record'); @@ -283,7 +292,7 @@ sub AddBiblio { # update MARC subfield that stores biblioitems.cn_sort _koha_marc_update_biblioitem_cn_sort( $record, $olddata, $frameworkcode ); - if (C4::Context->preference('AutoLinkBiblios')) { + if (!$disable_autolink && C4::Context->preference('BiblioAddsAuthorities')) { BiblioAutoLink( $record, $frameworkcode ); } @@ -589,6 +598,7 @@ sub BiblioAutoLink { my $record = shift; my $frameworkcode = shift; my $verbose = shift; + if (!$record) { carp('Undefined record passed to BiblioAutoLink'); return 0; diff --git a/misc/migration_tools/bulkmarcimport.pl b/misc/migration_tools/bulkmarcimport.pl index b9e961c911..dc2374c6a7 100755 --- a/misc/migration_tools/bulkmarcimport.pl +++ b/misc/migration_tools/bulkmarcimport.pl @@ -19,6 +19,7 @@ use C4::Biblio qw( ModBiblioMarc GetFrameworkCode GetMarcBiblio + BiblioAutoLink ); use C4::Koha; use C4::Charset qw( MarcToUTF8Record SetUTF8Flag ); @@ -125,6 +126,7 @@ if ($all) { my $using_elastic_search = (C4::Context->preference('SearchEngine') eq 'Elasticsearch'); my $modify_biblio_marc_options = { + disable_autolink => $using_elastic_search, defer_search_engine_indexing => $using_elastic_search, overlay_context => { source => 'bulkmarcimport' } }; @@ -541,7 +543,7 @@ RECORD: foreach my $record (@{$marc_records}) { } } elsif ($insert) { - eval { ($record_id, $biblioitemnumber) = AddBiblio($record, $framework, { defer_marc_save => 1 }) }; + eval { ($record_id, $biblioitemnumber) = AddBiblio($record, $framework, { disable_autolink => 1, defer_marc_save => 1 }) }; if ($@) { warn "ERROR: Insert biblio $originalid failed: $@\n"; printlog( { id => $originalid, op => "insert", status => "ERROR" } ) if ($logfile); @@ -645,6 +647,11 @@ RECORD: foreach my $record (@{$marc_records}) { $schema->txn_begin; if ($indexer) { $indexer->update_index(\@search_engine_record_ids, \@search_engine_records); + if (C4::Context->preference('BiblioAddsAuthorities')) { + foreach my $record (@search_engine_records) { + BiblioAutoLink($record, $framework); + } + } @search_engine_record_ids = (); @search_engine_records = (); } -- 2.39.5