=head2 ModBiblio
- ModBiblio( $record,$biblionumber,$frameworkcode);
+ ModBiblio( $record,$biblionumber,$frameworkcode, $disable_autolink);
Replace an existing bib record identified by C<$biblionumber>
with one supplied by the MARC::Record object C<$record>. The embedded
which fields are used to store embedded item, biblioitem,
and biblionumber data for indexing.
+Unless C<$disable_autolink> is passed ModBiblio will relink record headings
+to authorities based on settings in the system preferences. This flag allows
+us to not relink records when the authority linker is saving modifications.
+
Returns 1 on success 0 on failure
=cut
sub ModBiblio {
- my ( $record, $biblionumber, $frameworkcode ) = @_;
+ my ( $record, $biblionumber, $frameworkcode, $disable_autolink ) = @_;
if (!$record) {
carp 'No record passed to ModBiblio';
return 0;
logaction( "CATALOGUING", "MODIFY", $biblionumber, "biblio BEFORE=>" . $newrecord->as_formatted );
}
- if (C4::Context->preference('BiblioAddsAuthorities')) {
+ if ( !$disable_autolink && C4::Context->preference('BiblioAddsAuthorities') ) {
BiblioAutoLink( $record, $frameworkcode );
}
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);
}
use Modern::Perl;
-use Test::More tests => 11;
+use Test::More tests => 12;
use Test::MockModule;
use List::MoreUtils qw( uniq );
use MARC::Record;
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;