Bugzilla – Attachment 89976 Details for
Bug 22445
Ability to define a URL for custom cover images
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22445: Allow marc fields as pattern
Bug-22445-Allow-marc-fields-as-pattern.patch (text/plain), 2.73 KB, created by
Jonathan Druart
on 2019-05-23 02:40:26 UTC
(
hide
)
Description:
Bug 22445: Allow marc fields as pattern
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2019-05-23 02:40:26 UTC
Size:
2.73 KB
patch
obsolete
>From 52b6022994b50eef0bb4a97fc63fbf3402659b06 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Fri, 1 Mar 2019 09:04:28 -0300 >Subject: [PATCH] Bug 22445: Allow marc fields as pattern > >%tag$field% > >There is a limitation here, only one replacement will work. >Let see if it is needed later to support several patterns > >Sponsored-by: Orex Digital >--- > Koha/Biblio.pm | 10 ++++++++++ > t/db_dependent/Koha/Biblios.t | 25 +++++++++++++++++-------- > 2 files changed, 27 insertions(+), 8 deletions(-) > >diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm >index 35d508b203..eff5f58472 100644 >--- a/Koha/Biblio.pm >+++ b/Koha/Biblio.pm >@@ -676,6 +676,16 @@ sub custom_cover_image_url { > my $issn = $self->biblioitem->issn; > $url =~ s|%issn%|$issn|g; > } >+ >+ my $re = qr|%(?<field>\d{3})\$(?<subfield>.)%|; >+ if ( $url =~ $re ) { >+ my $field = $+{field}; >+ my $subfield = $+{subfield}; >+ my $marc_record = $self->metadata->record; >+ my $value = $marc_record->subfield($field, $subfield); >+ $url =~ s|$re|$value|; >+ } >+ > return $url; > } > >diff --git a/t/db_dependent/Koha/Biblios.t b/t/db_dependent/Koha/Biblios.t >index 09765228fd..2e7ce189e2 100644 >--- a/t/db_dependent/Koha/Biblios.t >+++ b/t/db_dependent/Koha/Biblios.t >@@ -21,6 +21,7 @@ use Modern::Perl; > > use Test::More tests => 6; > use Test::Exception; >+use MARC::Field; > > use C4::Items; > use C4::Biblio; >@@ -187,18 +188,26 @@ subtest 'can_be_transferred' => sub { > }; > > subtest 'custom_cover_image_url' => sub { >- plan tests => 1; >+ plan tests => 2; >+ > t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/%isbn%_%issn%.png' ); >+ > my $isbn = 'my_isbn'; > my $issn = 'my_issn'; >- my $biblioitem = $builder->build_object( >- { >- class => 'Koha::Biblioitems', >- value => { isbn => $isbn, issn => $issn } >- } >- ); >- my $biblio = Koha::Biblios->find( $biblioitem->biblionumber ); >+ my $marc_record = MARC::Record->new; >+ my ( $biblionumber, undef ) = C4::Biblio::AddBiblio($marc_record, ''); >+ >+ my $biblio = Koha::Biblios->find( $biblionumber ); >+ my $biblioitem = $biblio->biblioitem->set( >+ { isbn => $isbn, issn => $issn }); > is( $biblio->custom_cover_image_url, "https://my_url/${isbn}_${issn}.png" ); >+ >+ my $marc_024a = '710347104926'; >+ $marc_record->append_fields( MARC::Field->new( '024', '', '', a => $marc_024a ) ); >+ C4::Biblio::ModBiblio( $marc_record, $biblio->biblionumber ); >+ >+ t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/%024$a%.png' ); >+ is( $biblio->custom_cover_image_url, "https://my_url/$marc_024a.png" ); > }; > > $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 22445
:
85925
|
85926
|
85927
|
85928
|
85929
|
85930
|
85931
|
85932
|
85933
|
85934
|
85935
|
85936
|
85937
|
85938
|
86214
|
86726
|
86727
|
87434
|
89973
|
89974
|
89975
|
89976
|
89977
|
89978
|
89979
|
89980
|
89981
|
89982
|
89983
|
89984
|
89985
|
89986
|
89987
|
89988
|
89989
|
89996
|
89997
|
89998
|
89999
|
90000
|
90001
|
90002
|
90003
|
90004
|
90005
|
90006
|
90007
|
90009
|
90010
|
90011
|
90012
|
90013
|
94227
|
94228
|
94229
|
94230
|
94231
|
94232
|
94233
|
94234
|
94235
|
94236
|
94237
|
94238
|
94239
|
94240
|
94241
|
94242
|
94243
|
94244
|
94559
|
94560
|
94561
|
94562
|
94563
|
94564
|
94566
|
94567
|
94568
|
94569
|
94570
|
94571
|
94572
|
94573
|
94574
|
94575
|
94576
|
94577