Bugzilla – Attachment 113128 Details for
Bug 26921
Create cover image even when there is no record identificator
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26921: Don't generate an invalid custom cover image if the url cannot be generated
Bug-26921-Dont-generate-an-invalid-custom-cover-im.patch (text/plain), 20.82 KB, created by
Tomás Cohen Arazi (tcohen)
on 2020-11-05 18:22:48 UTC
(
hide
)
Description:
Bug 26921: Don't generate an invalid custom cover image if the url cannot be generated
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2020-11-05 18:22:48 UTC
Size:
20.82 KB
patch
obsolete
>From 6aa93127366c3559ba7ceb90a2ea89938f7de909 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 5 Nov 2020 16:02:14 +0100 >Subject: [PATCH] Bug 26921: Don't generate an invalid custom cover image if > the url cannot be generated > >In case a custom cover image url is used to generate the cover image of >bibliographic records, we should not build one if the record does not >have the necessary data. > >For instance if you have >CustomCoverImagesURL set to https://covers.openlibrary.org/b/isbn/{isbn}-M.jpb >and a biblio does not have the isbn defined, we should not generate and >empty image (empty or invalid src) > >Test plan: >0. >Set CustomCoverImagesURL to https://covers.openlibrary.org/b/isbn/{isbn}-M.jpb >Enable CustomCoverImages and OPACCustomCoverImages >To highlight the issue you should disable LocalCoverImages and OPACLocalCoverImages. >1. Make sure you have some of your bibliographic records with a valid >isbn >2. Make sure you have at least 1 bibliographic record without an isbn >set >3. Visit the search result and detail views (OPAC and staff interfaces) >=> Without this patch you should see a "Cover image" link, and an empty >block/div on the detail page >=> With this patch applied you should only see images when the url can >be generated > >Note that the problem will persist if the isbn is not valid (ie. no >image is generated) > >Sponsored-by: Orex Digital >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > Koha/Biblio.pm | 4 ++++ > .../prog/en/modules/catalogue/detail.tt | 15 +++++++++------ > .../prog/en/modules/catalogue/results.tt | 5 ++++- > .../bootstrap/en/includes/shelfbrowser.inc | 9 ++++++--- > .../bootstrap/en/modules/opac-detail.tt | 11 +++++++---- > .../bootstrap/en/modules/opac-opensearch.tt | 5 ++++- > .../bootstrap/en/modules/opac-results.tt | 11 +++++++---- > .../bootstrap/en/modules/opac-shelves.tt | 17 ++++++++++------- > .../en/modules/opac-showreviews-rss.tt | 5 ++++- > .../bootstrap/en/modules/opac-showreviews.tt | 5 ++++- > .../opac-tmpl/bootstrap/en/modules/opac-user.tt | 5 ++++- > t/db_dependent/Koha/Biblios.t | 6 +++++- > 12 files changed, 68 insertions(+), 30 deletions(-) > >diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm >index 29c7d1edb47..3aed9c7ee95 100644 >--- a/Koha/Biblio.pm >+++ b/Koha/Biblio.pm >@@ -757,14 +757,17 @@ sub custom_cover_image_url { > my $url = C4::Context->preference('CustomCoverImagesURL'); > if ( $url =~ m|{isbn}| ) { > my $isbn = $self->biblioitem->isbn; >+ return unless $isbn; > $url =~ s|{isbn}|$isbn|g; > } > if ( $url =~ m|{normalized_isbn}| ) { > my $normalized_isbn = C4::Koha::GetNormalizedISBN($self->biblioitem->isbn); >+ return unless $normalized_isbn; > $url =~ s|{normalized_isbn}|$normalized_isbn|g; > } > if ( $url =~ m|{issn}| ) { > my $issn = $self->biblioitem->issn; >+ return unless $issn; > $url =~ s|{issn}|$issn|g; > } > >@@ -774,6 +777,7 @@ sub custom_cover_image_url { > my $subfield = $+{subfield}; > my $marc_record = $self->metadata->record; > my $value = $marc_record->subfield($field, $subfield); >+ return unless $value; > $url =~ s|$re|$value|; > } > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt >index 1f9d0241dc4..861ec3cc8f9 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt >@@ -213,12 +213,15 @@ > [% END %] > > [% IF Koha.Preference('CustomCoverImages') && Koha.Preference('CustomCoverImagesURL') %] >- <div class="cover-image" id="custom-coverimg"> >- <a class="custom_cover_image" href="[% biblio.custom_cover_image_url | url %]"> >- <img id="custom-img" alt="Custom cover image" src="[% biblio.custom_cover_image_url | url %]" /> >- </a> >- <div class="hint">Custom cover image</div> >- </div> >+ [% SET custom_cover_image_url = biblio.custom_cover_image_url %] >+ [% IF custom_cover_image_url %] >+ <div class="cover-image" id="custom-coverimg"> >+ <a class="custom_cover_image" href="[% custom_cover_image_url | url %]"> >+ <img id="custom-img" alt="Custom cover image" src="[% custom_cover_image_url | url %]" /> >+ </a> >+ <div class="hint">Custom cover image</div> >+ </div> >+ [% END %] > [% END %] > </div> <!-- /.cover-slider --> > </div> <!-- /.bookcoverimg.col-xs-3 --> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt >index b8f19814eae..ebb64f26cee 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt >@@ -453,7 +453,10 @@ > [% END %] > > [% IF Koha.Preference('CustomCoverImages') && Koha.Preference('CustomCoverImagesURL') %] >- <a class="custom_cover_image" href="[% SEARCH_RESULT.biblio_object.custom_cover_image_url | url %]"><img alt="Cover image" src="[% SEARCH_RESULT.biblio_object.custom_cover_image_url | url %]" /> >+ [% SET custom_cover_image_url = SEARCH_RESULT.biblio_object.custom_cover_image_url %] >+ [% IF custom_cover_image_url %] >+ <a class="custom_cover_image" href="[% custom_cover_image_url | url %]"><img alt="Cover image" src="[% custom_cover_image_url | url %]" /> >+ [% END %] > [% END %] > </td> > [% END # /IF( AmazonCoverImages || LocalCoverImages || AdlibrisEnabled || IntranetCoce )%] >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/shelfbrowser.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/shelfbrowser.inc >index 396470d977e..84f2b3082c0 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/shelfbrowser.inc >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/shelfbrowser.inc >@@ -71,9 +71,12 @@ > [% END %] > [% END %] > [% IF Koha.Preference('OPACCustomCoverImages') AND Koha.Preference('CustomCoverImagesURL') %] >- <span class="custom_cover_image"> >- <img alt="Cover image" src="[% item.biblio_object.custom_cover_image_url | url %]" /> >- </span> >+ [% SET custom_cover_image_url = item.biblio_object.custom_cover_image_url %] >+ [% IF custom_cover_image_url %] >+ <span class="custom_cover_image"> >+ <img alt="Cover image" src="[% custom_cover_image_url | url %]" /> >+ </span> >+ [% END %] > [% END %] > > </a> >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt >index 4e0d27de9ec..1f0d336a737 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt >@@ -113,10 +113,13 @@ > [% END %] > [% END %] > [% IF Koha.Preference('OPACCustomCoverImages') AND Koha.Preference('CustomCoverImagesURL') %] >- [% IF ( OPACURLOpenInNewWindow ) %] >- <a class="custom_cover_image" href="[% biblio.custom_cover_image_url | url %]" target="_blank" rel="noreferrer"><img alt="Cover image" src="[% biblio.custom_cover_image_url | url %]" /></a> >- [% ELSE %] >- <a class="custom_cover_image" href="[% biblio.custom_cover_image_url | url %]"><img alt="Cover image" src="[% biblio.custom_cover_image_url | url %]" /></a> >+ [% SET custom_cover_image_url = biblio.custom_cover_image_url %] >+ [% IF custom_cover_image_url %] >+ [% IF ( OPACURLOpenInNewWindow ) %] >+ <a class="custom_cover_image" href="[% custom_cover_image_url | url %]" target="_blank" rel="noreferrer"><img alt="Cover image" src="[% custom_cover_image_url | url %]" /></a> >+ [% ELSE %] >+ <a class="custom_cover_image" href="[% custom_cover_image_url | url %]"><img alt="Cover image" src="[% custom_cover_image_url | url %]" /></a> >+ [% END %] > [% END %] > [% END %] > </div><!-- / #bookcover --> >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-opensearch.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-opensearch.tt >index 4a12cdeb84d..a423f8f5c38 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-opensearch.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-opensearch.tt >@@ -66,7 +66,10 @@ > [% IF ( BakerTaylorEnabled ) %][% IF bt_id %]<a href="https://[% BakerTaylorBookstoreURL |url %][% bt_id | uri %]"><img alt="See Baker & Taylor" src="[% BakerTaylorImageURL |url %][% bt_id | uri %]" /></a>[% END %][% END %] > > [% IF Koha.Preference('OPACCustomCoverImages') AND Koha.Preference('CustomCoverImagesURL') %] >- <img alt="Cover image" src="[% SEARCH_RESULT.biblio_object.custom_cover_image_url | url %]" /> >+ [% SET custom_cover_image_url = SEARCH_RESULT.biblio_object.custom_cover_image_url %] >+ [% IF custom_cover_image_url %] >+ <img alt="Cover image" src="[% custom_cover_image_url | url %]" /> >+ [% END %] > [% END %] > > <p>[% IF ( SEARCH_RESULT.author ) %]By [% SEARCH_RESULT.author | html %]. [% END %] >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt >index 34b27c0ccd0..26d3db9f8aa 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt >@@ -371,10 +371,13 @@ > [% END %] > > [% IF Koha.Preference('OPACCustomCoverImages') AND Koha.Preference('CustomCoverImagesURL') %] >- [% IF ( OPACURLOpenInNewWindow ) %] >- <a class="custom_cover_image" href="[% SEARCH_RESULT.biblio_object.custom_cover_image_url | url %]" target="_blank" rel="noreferrer"><img alt="Cover image" src="[% SEARCH_RESULT.biblio_object.custom_cover_image_url | url %]" /></a> >- [% ELSE %] >- <a class="custom_cover_image" href="[% SEARCH_RESULT.biblio_object.custom_cover_image_url | url %]"><img alt="Cover image" src="[% SEARCH_RESULT.biblio_object.custom_cover_image_url | url %]" /></a> >+ [% SET custom_cover_image_url = SEARCH_RESULT.biblio_object.custom_cover_image_url %] >+ [% IF custom_cover_image_url %] >+ [% IF ( OPACURLOpenInNewWindow ) %] >+ <a class="custom_cover_image" href="[% custom_cover_image_url | url %]" target="_blank" rel="noreferrer"><img alt="Cover image" src="[% custom_cover_image_url | url %]" /></a> >+ [% ELSE %] >+ <a class="custom_cover_image" href="[% custom_cover_image_url | url %]"><img alt="Cover image" src="[% custom_cover_image_url | url %]" /></a> >+ [% END %] > [% END %] > [% END %] > >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt >index aa108764ad2..4ee6813fc73 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt >@@ -453,16 +453,19 @@ > [% END %] > > [% IF Koha.Preference('OPACCustomCoverImages') AND Koha.Preference('CustomCoverImagesURL') %] >- [% IF ( itemsloo.BiblioDefaultViewmarc ) %] >- <a class="custom_cover_image" href="/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=[% itemsloo.biblionumber |url %]"> >- [% ELSE %] >- [% IF ( itemsloo.BiblioDefaultViewisbd ) %] >- <a class="custom_cover_image" href="/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=[% itemsloo.biblionumber |url %]"> >+ [% SET custom_cover_image_url = itemsloo.biblio_object.custom_cover_image_url %] >+ [% IF custom_cover_image_url %] >+ [% IF ( itemsloo.BiblioDefaultViewmarc ) %] >+ <a class="custom_cover_image" href="/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=[% itemsloo.biblionumber |url %]"> > [% ELSE %] >- <a class="custom_cover_image" href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% itemsloo.biblionumber |url %]"> >+ [% IF ( itemsloo.BiblioDefaultViewisbd ) %] >+ <a class="custom_cover_image" href="/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=[% itemsloo.biblionumber |url %]"> >+ [% ELSE %] >+ <a class="custom_cover_image" href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% itemsloo.biblionumber |url %]"> >+ [% END %] > [% END %] >+ <img alt="Cover image" src="[% custom_cover_image_url | url %]" /></a> > [% END %] >- <img alt="Cover image" src="[% itemsloo.biblio_object.custom_cover_image_url | url %]" /></a> > [% END %] > > </div> >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-showreviews-rss.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-showreviews-rss.tt >index 12e92aa3c5b..bb432de1375 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-showreviews-rss.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-showreviews-rss.tt >@@ -25,7 +25,10 @@ > [% IF ( BakerTaylorEnabled && bt_id ) %]<a href="https://[% BakerTaylorBookstoreURL | uri %][% bt_id | uri %]"><img alt="See Baker & Taylor" src="[% BakerTaylorImageURL | html %][% bt_id | html %]" /></a>[% END %] > > [% IF Koha.Preference('OPACCustomCoverImages') AND Koha.Preference('CustomCoverImagesURL') %] >- <a href="[% review.biblio_object.custom_cover_image_url | url %]"><img alt="Cover image" src="[% review.biblio_object.custom_cover_image_url | url %]" /></a> >+ [% SET custom_cover_image_url = review.biblio_object.custom_cover_image_url %] >+ [% IF custom_cover_image_url %] >+ <a href="[% custom_cover_image_url | url %]"><img alt="Cover image" src="[% custom_cover_image_url | url %]" /></a> >+ [% END %] > [% END %] > > [% IF ( review.author ) %]<p>By [% review.author | html %].</p> [% END %] >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-showreviews.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-showreviews.tt >index cdfe84a4ace..010a1766c62 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-showreviews.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-showreviews.tt >@@ -158,7 +158,10 @@ > [% END %] > > [% IF Koha.Preference('OPACCustomCoverImages') AND Koha.Preference('CustomCoverImagesURL') %] >- <a class="custom_cover_image" href="[% review.biblio_object.custom_cover_image_url | url %]"><img alt="Cover image" src="[% review.biblio_object.custom_cover_image_url | url %]" /></a> >+ [% SET custom_cover_image_url = review.biblio_object.custom_cover_image_url %] >+ [% IF custom_cover_image_url %] >+ <a class="custom_cover_image" href="[% custom_cover_image_url | url %]"><img alt="Cover image" src="[% custom_cover_image_url | url %]" /></a> >+ [% END %] > [% END %] > > </td> >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt >index 548af38171b..c623e6d98fb 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt >@@ -292,7 +292,10 @@ > [% END %] > > [% IF Koha.Preference('OPACCustomCoverImages') AND Koha.Preference('CustomCoverImagesURL') %] >- <a class="custom_cover_image" href="[% ISSUE.biblio_object.custom_cover_image_url | url %]"><img alt="Cover image" src="[% ISSUE.biblio_object.custom_cover_image_url | url %]" /></a> >+ [% SET custom_cover_image_url = ISSUE.biblio_object.custom_cover_image_url %] >+ [% IF custom_cover_image_url %] >+ <a class="custom_cover_image" href="[% custom_cover_image_url | url %]"><img alt="Cover image" src="[% custom_cover_image_url | url %]" /></a> >+ [% END %] > [% END %] > > [% IF ( SyndeticsEnabled && SyndeticsCoverImages ) %] >diff --git a/t/db_dependent/Koha/Biblios.t b/t/db_dependent/Koha/Biblios.t >index fcba56dcd77..82229f1f353 100755 >--- a/t/db_dependent/Koha/Biblios.t >+++ b/t/db_dependent/Koha/Biblios.t >@@ -189,7 +189,7 @@ subtest 'can_be_transferred' => sub { > }; > > subtest 'custom_cover_image_url' => sub { >- plan tests => 3; >+ plan tests => 4; > > t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{isbn}_{issn}.png' ); > >@@ -213,6 +213,10 @@ subtest 'custom_cover_image_url' => sub { > t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{normalized_isbn}.png' ); > my $normalized_isbn = C4::Koha::GetNormalizedISBN($isbn); > is( $biblio->custom_cover_image_url, "https://my_url/$normalized_isbn.png" ); >+ >+ $biblio->biblioitem->isbn('')->store; >+ is( $biblio->custom_cover_image_url, undef, "Don't generate the url if the biblio does not have the value needed to generate it" ); >+ > }; > > $schema->storage->txn_rollback; >-- >2.29.2
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 26921
:
113124
|
113128
|
114452