From d6eb0657ba91ce4d5600e3d37ba3ff7c63690a0b Mon Sep 17 00:00:00 2001 From: David Nind Date: Sat, 25 Jan 2025 00:02:52 +0000 Subject: [PATCH] Bug 38963: Check for existence of biblio object before fetching cover images in the OPAC This patch adds a conditional to ensure the biblio object has been retrieved and assumes no cover images otherwise. This is similar to bug 37425 that fixed the issue for the staff interface. Test plan: 1. Enable the OPACLocalCoverImages system preference. 2. Search in the OPAC (for example, attic). 3. Find the biblionumber for one of the results and delete it from the database using SQL: DELETE FROM biblio WHERE biblionumber=3; 4. Search again. NOTE: Steps 3 and 4 need to be done very quickly to generate the error. I had the terminal open with the SQL already loaded, and the browser also open. 5. Error trace generated: Can't call method "cover_images" on an undefined value at /kohadevbox/koha/opac/opac-search.pl line 702. at /kohadevbox/koha/opac/opac-search.pl line 701 6. Reindex, confirm error is gone: koha-rebuild-zebra -d -f -v kohadev 7. Apply the patch. 8. Repeat steps 2 to 4 - I searched for perl and used biblionumber 13. 9. No error generated 10. Reindex and repeat search and confirm no error. Signed-off-by: David Nind --- opac/opac-search.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opac/opac-search.pl b/opac/opac-search.pl index 54eabd8949..d52f96d01a 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -699,7 +699,7 @@ for (my $i=0;$i<@servers;$i++) { $res->{artreqpossible} = ( $art_req_itypes->{ $res->{itemtype} // q{} } || $art_req_itypes->{ '*' } ) ? 1 : q{}; if ( C4::Context->preference('OPACLocalCoverImages') ) { - $res->{has_local_cover_image} = $res->{biblio_object}->cover_images->count; + $res->{has_local_cover_image} = $res->{biblio_object} ? $res->{biblio_object}->cover_images->count : 0; } } -- 2.39.5