From 1e4126a0e3ad5a9f65b168af5f384b4c1461ddc6 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Mon, 10 Apr 2017 12:32:11 +0000 Subject: [PATCH] Bug 18408: Store $record in Koha::Biblio and invalidate it when ->store --- Koha/Biblio.pm | 15 ++++++++++++++- t/db_dependent/Koha/Biblios.t | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 2e7b6e2..5fc47c9 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -381,10 +381,23 @@ Returns the Remainder of title, 245$b. sub title_remainder { my ($self) = @_; - return unless my $record = C4::Biblio::GetMarcBiblio($self->biblionumber); + $self->{_record} ||= C4::Biblio::GetMarcBiblio($self->biblionumber); + return unless my $record = $self->{_record}; return $record->subfield('245','b'); } +=head3 store + +=cut + +sub store { + my ($self) = @_; + + $self->{_record} = undef; + + $self->SUPER::store; +} + =head3 type =cut diff --git a/t/db_dependent/Koha/Biblios.t b/t/db_dependent/Koha/Biblios.t index b46d433..0a3d5dd 100644 --- a/t/db_dependent/Koha/Biblios.t +++ b/t/db_dependent/Koha/Biblios.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 3; +use Test::More tests => 4; use C4::Biblio; use C4::Items; @@ -125,6 +125,19 @@ subtest 'title_remainder' => sub { is($biblio->title_remainder, 'Remainder', 'Got remainder of title'); }; +subtest 'store' => sub { + plan tests => 2; + + my ($bibnum, $title, $bibitemnum) = create_helper_biblio('BK'); + + my $biblio = Koha::Biblios->find($bibnum); + $biblio->title_remainder; + is(ref($biblio->{_record}), 'MARC::Record', + 'MARC::Record is cached in the object'); + $biblio->store; + is($biblio->{_record}, undef, 'store invalidates ->{_record}'); +}; + $schema->storage->txn_rollback; -- 2.7.4