Bugzilla – Attachment 57653 Details for
Bug 17642
Authorised values code is broken because of the refactoring
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17642: Add get_description_by_koha_field
Bug-17642-Add-getdescriptionbykohafield.patch (text/plain), 4.29 KB, created by
Martin Renvoize (ashimema)
on 2016-11-18 15:51:12 UTC
(
hide
)
Description:
Bug 17642: Add get_description_by_koha_field
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2016-11-18 15:51:12 UTC
Size:
4.29 KB
patch
obsolete
>From 74530f8761f394e133ba0424bc3af339af7f1230 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 16 Nov 2016 17:23:23 +0100 >Subject: [PATCH] Bug 17642: Add get_description_by_koha_field > >Most of the time we just need the descriptions (lib or >opac_description), so let's add a new method for that and cache the >descriptions in L1. >Ideally we should cache it in L2 as well, but the AV code is not robust >enough to allow that > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > Koha/AuthorisedValues.pm | 20 ++++++++++++++++++++ > t/db_dependent/AuthorisedValues.t | 31 +++++++++++++++++++++++++++++-- > 2 files changed, 49 insertions(+), 2 deletions(-) > >diff --git a/Koha/AuthorisedValues.pm b/Koha/AuthorisedValues.pm >index 55bf85d..ad68904 100644 >--- a/Koha/AuthorisedValues.pm >+++ b/Koha/AuthorisedValues.pm >@@ -25,6 +25,7 @@ use Koha::Database; > > use Koha::AuthorisedValue; > use Koha::MarcSubfieldStructures; >+use Koha::Cache::Memory::Lite; > > use base qw(Koha::Objects); > >@@ -119,6 +120,25 @@ sub find_by_koha_field { > return $av->count ? $av->next : undef; > } > >+sub get_description_by_koha_field { >+ my ( $self, $params ) = @_; >+ my $frameworkcode = $params->{frameworkcode} || ''; >+ my $kohafield = $params->{kohafield}; >+ my $authorised_value = $params->{authorised_value}; >+ >+ return {} unless defined $authorised_value; >+ >+ my $memory_cache = Koha::Cache::Memory::Lite->get_instance; >+ my $cache_key = "Av_descriptions:$frameworkcode:$kohafield:$authorised_value"; >+ my $cached = $memory_cache->get_from_cache($cache_key); >+ return $cached if $cached; >+ >+ my $av = $self->find_by_koha_field($params); >+ my $descriptions = { lib => $av->lib, opac_description => $av->opac_description }; >+ $memory_cache->set_in_cache( $cache_key, $descriptions ); >+ return $descriptions; >+} >+ > sub categories { > my ( $self ) = @_; > my $rs = $self->_resultset->search( >diff --git a/t/db_dependent/AuthorisedValues.t b/t/db_dependent/AuthorisedValues.t >index bde3e2d..7295d41 100644 >--- a/t/db_dependent/AuthorisedValues.t >+++ b/t/db_dependent/AuthorisedValues.t >@@ -118,8 +118,8 @@ is( @categories, 3, 'There should have 2 categories inserted' ); > is( $categories[0], $av4->category, 'The first category should be correct (ordered by category name)' ); > is( $categories[1], $av1->category, 'The second category should be correct (ordered by category name)' ); > >-subtest 'search_by_*_field + find_by_koha_field' => sub { >- plan tests => 3; >+subtest 'search_by_*_field + find_by_koha_field + search_for_descriptions' => sub { >+ plan tests => 4; > my $loc_cat = Koha::AuthorisedValueCategories->find('LOC'); > $loc_cat->delete if $loc_cat; > my $mss = Koha::MarcSubfieldStructures->search( { tagfield => 952, tagsubfield => 'c', frameworkcode => '' } ); >@@ -173,4 +173,31 @@ subtest 'search_by_*_field + find_by_koha_field' => sub { > $av = Koha::AuthorisedValues->find_by_koha_field( { kohafield => 'items.restricted', authorised_value => undef } ); > is( $av, undef, ); > }; >+ subtest 'get_description_by_koha_field' => sub { >+ plan tests => 3; >+ my $descriptions; >+ >+ # Test authorised_value = 0 >+ $descriptions = Koha::AuthorisedValues->get_description_by_koha_field( >+ { kohafield => 'items.restricted', authorised_value => 0 } ); >+ is_deeply( $descriptions, >+ { lib => $av_0->lib, opac_description => $av_0->lib_opac }, >+ ); >+ >+ # Test authorised_value = "" >+ $descriptions = Koha::AuthorisedValues->get_description_by_koha_field( >+ { kohafield => 'items.restricted', authorised_value => '' } ); >+ is_deeply( >+ $descriptions, >+ { >+ lib => $av_empty_string->lib, >+ opac_description => $av_empty_string->lib_opac >+ }, >+ ); >+ >+ # Test authorised_value = undef => we do not want to retrieve anything >+ $descriptions = Koha::AuthorisedValues->get_description_by_koha_field( >+ { kohafield => 'items.restricted', authorised_value => undef } ); >+ is_deeply( $descriptions, {}, ) ; # This could be arguable, we could return undef instead >+ }; > }; >-- >2.1.4
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 17642
:
57533
|
57569
|
57570
|
57571
|
57572
|
57573
|
57574
|
57595
|
57616
|
57628
|
57629
|
57630
|
57631
|
57632
|
57633
|
57634
|
57635
|
57650
|
57651
|
57652
| 57653 |
57654
|
57655
|
57656
|
57657