Bugzilla – Attachment 88161 Details for
Bug 21957
LinkBibHeadingsToAuthorities can be called twice when running link_bibs_to_authorities
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21957: Add a flag to ModBiblio to avoid linking auths if called from linker
Bug-21957-Add-a-flag-to-ModBiblio-to-avoid-linking.patch (text/plain), 4.51 KB, created by
Josef Moravec
on 2019-04-17 10:21:40 UTC
(
hide
)
Description:
Bug 21957: Add a flag to ModBiblio to avoid linking auths if called from linker
Filename:
MIME Type:
Creator:
Josef Moravec
Created:
2019-04-17 10:21:40 UTC
Size:
4.51 KB
patch
obsolete
>From f7ab582fe0c74915369177c2cc62b5b28bcf77c0 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Wed, 5 Dec 2018 21:05:32 +0000 >Subject: [PATCH] Bug 21957: Add a flag to ModBiblio to avoid linking auths if > called from linker > >To test: >1 - prove -v t/db_dependent/Biblio.t >2 - Set BiblioAddsAuthoorities and AutoCreateAuthorities >3 - Modify a biblio to add a heading with no existing auth record >4 - Ensure the record was created on saving >5 - Ensure that editing works as normal otherwise >6 - Run link_bibs_to_authorities >7 - Ensure results are as expected > >Signed-off-by: Michal Denar <black23@gmail.com> > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> >--- > C4/Biblio.pm | 12 +++++++----- > misc/link_bibs_to_authorities.pl | 3 ++- > t/db_dependent/Biblio.t | 19 ++++++++++++++++++- > 3 files changed, 27 insertions(+), 7 deletions(-) > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index 13926ef939..d7c749144b 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -240,7 +240,7 @@ sub AddBiblio { > > =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 >@@ -256,12 +256,16 @@ in the C<biblio> and C<biblioitems> tables, as well as > 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; >@@ -272,7 +276,7 @@ sub ModBiblio { > logaction( "CATALOGUING", "MODIFY", $biblionumber, "biblio BEFORE=>" . $newrecord->as_formatted ); > } > >- if (C4::Context->preference('BiblioAddsAuthorities')) { >+ if ( !$disable_autolink && C4::Context->preference('BiblioAddsAuthorities') ) { > BiblioAutoLink( $record, $frameworkcode ); > } > >@@ -624,12 +628,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); > } > >diff --git a/misc/link_bibs_to_authorities.pl b/misc/link_bibs_to_authorities.pl >index 699451a8aa..1fd75a51e1 100755 >--- a/misc/link_bibs_to_authorities.pl >+++ b/misc/link_bibs_to_authorities.pl >@@ -221,7 +221,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++; > } > } >diff --git a/t/db_dependent/Biblio.t b/t/db_dependent/Biblio.t >index 60ccde3a18..dd96e546ff 100755 >--- a/t/db_dependent/Biblio.t >+++ b/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; >@@ -570,6 +570,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; >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 21957
:
82893
|
84313
|
88001
|
88033
| 88161