@@ -, +, @@ called from linker --- C4/Biblio.pm | 6 ++---- misc/link_bibs_to_authorities.pl | 3 ++- t/db_dependent/Biblio.t | 19 ++++++++++++++++++- 3 files changed, 22 insertions(+), 6 deletions(-) --- a/C4/Biblio.pm +++ a/C4/Biblio.pm @@ -262,7 +262,7 @@ Returns 1 on success 0 on failure =cut sub ModBiblio { - my ( $record, $biblionumber, $frameworkcode ) = @_; + my ( $record, $biblionumber, $frameworkcode, $called_by_linker ) = @_; if (!$record) { carp 'No record passed to ModBiblio'; return 0; @@ -273,7 +273,7 @@ sub ModBiblio { logaction( "CATALOGUING", "MODIFY", $biblionumber, "biblio BEFORE=>" . $newrecord->as_formatted ); } - if (C4::Context->preference('BiblioAddsAuthorities')) { + if (C4::Context->preference('BiblioAddsAuthorities') && !$called_by_linker) { BiblioAutoLink( $record, $frameworkcode ); } @@ -622,12 +622,10 @@ safest place. sub _check_valid_auth_link { my ( $authid, $field ) = @_; - require C4::AuthoritiesMarc; my $authorized_heading = C4::AuthoritiesMarc::GetAuthorizedHeading( { 'authid' => $authid } ) || ''; - return ($field->as_string('abcdefghijklmnopqrstuvwxyz') eq $authorized_heading); } --- a/misc/link_bibs_to_authorities.pl +++ a/misc/link_bibs_to_authorities.pl @@ -220,7 +220,8 @@ sub process_bib { ); } if ( not $test_only ) { - ModBiblio( $bib, $biblionumber, $frameworkcode ); + ModBiblio( $bib, $biblionumber, $frameworkcode, 1 ); + #Last param is to note ModBiblio was called from linking script and bib should not be linked again $num_bibs_modified++; } } --- a/t/db_dependent/Biblio.t +++ a/t/db_dependent/Biblio.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 11; +use Test::More tests => 12; use Test::MockModule; use List::MoreUtils qw( uniq ); use MARC::Record; @@ -495,6 +495,23 @@ subtest 'MarcFieldForCreatorAndModifier' => sub { is($record->subfield('998', 'd'), 'Jane Doe', '998$d = Jane Doe'); }; +subtest 'ModBiblio called from linker test' => sub { + plan tests => 2; + my $called = 0; + t::lib::Mocks::mock_preference('BiblioAddsAuthorities', 1); + my $biblio_mod = Test::MockModule->new( 'C4::Biblio' ); + $biblio_mod->mock( 'LinkBibHeadingsToAuthorities', sub { + $called = 1; + }); + my $record = MARC::Record->new(); + my ($biblionumber) = C4::Biblio::AddBiblio($record,''); + C4::Biblio::ModBiblio($record,$biblionumber,''); + is($called,1,"We called to link bibs because not from linker"); + $called = 0; + C4::Biblio::ModBiblio($record,$biblionumber,'',1); + is($called,0,"We didn't call to link bibs because from linker"); +}; + # Cleanup Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" ); $schema->storage->txn_rollback; --