Bugzilla – Attachment 159001 Details for
Bug 35343
record method, required for bug 26611, missing from Koha::Authority
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35343: Add record accessor method to Koha::Authority
Bug-35343-Add-record-accessor-method-to-KohaAuthor.patch (text/plain), 3.50 KB, created by
Martin Renvoize
on 2023-11-15 17:14:49 UTC
(
hide
)
Description:
Bug 35343: Add record accessor method to Koha::Authority
Filename:
MIME Type:
Creator:
Martin Renvoize
Created:
2023-11-15 17:14:49 UTC
Size:
3.50 KB
patch
obsolete
>From 4df489d3308779a88e26bcda0328d3b62a7d7e03 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Tue, 6 Dec 2022 17:07:02 -0300 >Subject: [PATCH] Bug 35343: Add record accessor method to Koha::Authority > >Code lifted from bug 31794 to fix already backported bug 26611. > >Unit tests included. > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/Authority.pm | 28 ++++++++++++++++------- > t/db_dependent/Koha/Authorities.t | 38 ++++++++++++++++++++++++++++++- > 2 files changed, 57 insertions(+), 9 deletions(-) > >diff --git a/Koha/Authority.pm b/Koha/Authority.pm >index ff45d20a3dd..828d4c75b26 100644 >--- a/Koha/Authority.pm >+++ b/Koha/Authority.pm >@@ -95,8 +95,7 @@ sub controlled_indicators { > ? 'UNIMARCAUTH' > : 'MARC21'; > if( !$record ) { >- $record = MARC::Record->new_from_xml( >- $self->marcxml, 'UTF-8', $flavour ); >+ $record = $self->record; > } > > if( !$self->{_report_tag} ) { >@@ -125,12 +124,7 @@ Return a list of identifiers of the authors which are in 024$2$a > sub get_identifiers { > my ( $self, $params ) = @_; > >- my $flavour = >- C4::Context->preference('marcflavour') eq 'UNIMARC' >- ? 'UNIMARCAUTH' >- : 'MARC21'; >- my $record = >- MARC::Record->new_from_xml( $self->marcxml, 'UTF-8', $flavour ); >+ my $record = $self->record; > > my @identifiers; > for my $field ( $record->field('024') ) { >@@ -143,6 +137,24 @@ sub get_identifiers { > return \@identifiers; > } > >+=head3 record >+ >+ my $record = $authority->record() >+ >+Return the MARC::Record for this authority >+ >+=cut >+ >+sub record { >+ my ( $self ) = @_; >+ >+ my $flavour = >+ C4::Context->preference('marcflavour') eq 'UNIMARC' >+ ? 'UNIMARCAUTH' >+ : 'MARC21'; >+ return MARC::Record->new_from_xml( $self->marcxml, 'UTF-8', $flavour ); >+} >+ > =head2 Class Methods > > =head3 type >diff --git a/t/db_dependent/Koha/Authorities.t b/t/db_dependent/Koha/Authorities.t >index 5dbfaaa4973..699ee1c34a2 100755 >--- a/t/db_dependent/Koha/Authorities.t >+++ b/t/db_dependent/Koha/Authorities.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 8; >+use Test::More tests => 9; > use MARC::Field; > use MARC::File::XML; > use MARC::Record; >@@ -285,4 +285,40 @@ subtest 'get_identifiers' => sub { > ); > }; > >+subtest 'record tests' => sub { >+ plan tests => 3; >+ >+ t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); >+ my $record = MARC::Record->new(); >+ $record->add_fields( >+ [ >+ '100', ' ', ' ', >+ a => 'Lastname, Firstname', >+ b => 'b', >+ c => 'c', >+ i => 'i' >+ ], >+ [ >+ '024', '', '', >+ a => '0000-0002-1234-5678', >+ 2 => 'orcid', >+ 6 => 'https://orcid.org/0000-0002-1234-5678' >+ ], >+ [ >+ '024', '', '', >+ a => '01234567890', >+ 2 => 'scopus', >+ 6 => 'https://www.scopus.com/authid/detail.uri?authorId=01234567890' >+ ], >+ ); >+ my $authid = C4::AuthoritiesMarc::AddAuthority($record, undef, 'PERSO_NAME'); >+ my $authority = Koha::Authorities->find($authid); >+ my $authority_record = $authority->record; >+ is ($authority_record->field('100')->subfield('a'), 'Lastname, Firstname'); >+ my @fields_024 = $authority_record->field('024'); >+ is ($fields_024[0]->subfield('a'), '0000-0002-1234-5678'); >+ is ($fields_024[1]->subfield('a'), '01234567890'); >+ >+}; >+ > $schema->storage->txn_rollback; >-- >2.41.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 35343
: 159001