From d0d61eca0281f4f007863934d54716fac4e39f09 Mon Sep 17 00:00:00 2001 From: Victor Grousset Date: Fri, 20 Apr 2018 11:17:26 +0200 Subject: [PATCH] Bug 20623 : Fix basket group PDF when itemtype not itemtype table MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When an item has an itemtype not in the itemtype table. Trying to fetch it's description lead to an error. Using authorized values like ccode to populate the itemtypes of the biblioitems (instead of the itemtype table) can lead to such data. Or importing records with invalid itemtype codes. Koha doesn't do enough checks at import to at least warn about these issues. == Test plan == 1. have/create a budget 2. have/create a fund 3. have/create a vendor with minimal info 4. create a basket with minimal info 5. add a item to the basket 6. go to the basket. URL should be /cgi-bin/koha/acqui/basket.pl?basketno=XXXXX 7. close this basket 8. create a basket group with the basket - your vendor page => Basket groups - create basket group - (tick the "close this basket group" check box) 9. go to the basket group your vendor page => Basket groups => Closed 10. export as PDF, it should work, keep the page opened 11. find the itemtype code of item in the basket 12. delete it with the following SQL[1] (directly or use sql reports) replace with the relevant type code DELETE from itemtypes where itemtype = "BOOK"; 13. reexport the basket as PDF 14. it should fail (internal server error) this is the bug (no kidding ^^) 15. apply this patch 16. reexport the basket as PDF 17. it should work 18. create an item type (in administration) that has the same code as the deleted one 19. reexport the basket as PDF 20. check that in the PDF that the description is here: table at the bottom of the document → "Document" column [1] Or you can find a more realistic way to have a biblioitem whose itemtype is not in the itemtype table --- acqui/basketgroup.pl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/acqui/basketgroup.pl b/acqui/basketgroup.pl index 8c0e4c4..5172287 100755 --- a/acqui/basketgroup.pl +++ b/acqui/basketgroup.pl @@ -195,7 +195,10 @@ sub printbasketgrouppdf{ } } - $ord->{itemtype} = ( $ord->{itemtype} and $biblioitem->itemtype ) ? Koha::ItemTypes->find( $biblioitem->itemtype )->description : undef; + my $item_has_type_description = ($ord->{itemtype} + and $biblioitem->itemtype + and Koha::ItemTypes->find( $biblioitem->itemtype )); + $ord->{itemtype} = $item_has_type_description ? Koha::ItemTypes->find( $biblioitem->itemtype )->description : undef; $ord->{en} = $en ? $en : undef; $ord->{edition} = $edition ? $edition : undef; -- 2.7.4