From 926b5aee57b7da819217b58dba694c273e765f99 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 22 Nov 2022 09:34:44 +0100 Subject: [PATCH] Bug 32262: Handle non-existing circ rules Some rules are not displayed on the UI, even if they exist in the DB, that's confusing. That's because we are implicitely returning 'undef' from CirculationRules.Search, and perl returns an empty string for undef in a string context. Which means "rules.defined" is always true. This patch is ugly and really hope somebody else will come with a better solution. Test plan: I don't know, search for regressions on the circ rule UI?... :D --- Koha/Template/Plugin/CirculationRules.pm | 1 + .../prog/en/modules/admin/smart-rules.tt | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Koha/Template/Plugin/CirculationRules.pm b/Koha/Template/Plugin/CirculationRules.pm index 5e00e456380..a295599a074 100644 --- a/Koha/Template/Plugin/CirculationRules.pm +++ b/Koha/Template/Plugin/CirculationRules.pm @@ -88,6 +88,7 @@ sub Search { return $rule if $params->{want_rule}; return $rule->rule_value if $rule; + return 'undef'; } =head3 Renewals diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt index 593b9dab8ee..b4ff7c4dced 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt @@ -812,7 +812,7 @@ [% SET patron_maxonsiteissueqty = CirculationRules.Search( branchcode, c, undef, 'patron_maxonsiteissueqty' ) %] [% SET max_holds = CirculationRules.Search( branchcode, c, undef, 'max_holds' ) %] - [% IF ( patron_maxissueqty.defined && patron_maxissueqty != '' ) || ( patron_maxonsiteissueqty.defined && patron_maxonsiteissueqty != '' ) || ( max_holds.defined && max_holds != '' ) %] + [% IF patron_maxissueqty != 'undef' || patron_maxonsiteissueqty != 'undef' || max_holds != 'undef' %] [% IF c == undef %] @@ -822,21 +822,21 @@ [% END %] - [% IF patron_maxissueqty.defined && patron_maxissueqty != '' %] + [% IF patron_maxissueqty != '' && patron_maxissueqty != 'undef' %] [% patron_maxissueqty | html %] [% ELSE %] Unlimited [% END %] - [% IF patron_maxonsiteissueqty.defined && patron_maxonsiteissueqty != '' %] + [% IF patron_maxonsiteissueqty != '' && patron_maxonsiteissueqty != 'undef' %] [% patron_maxonsiteissueqty | html %] [% ELSE %] Unlimited [% END %] - [% IF max_holds.defined && max_holds != '' %] + [% IF max_holds != '' && max_holds != 'undef' %] [% max_holds | html %] [% ELSE %] Unlimited @@ -891,7 +891,7 @@ [% SET waiting_hold_cancellation = CirculationRules.Search( current_branch, c, i, 'waiting_hold_cancellation' ) %] - [% IF ( waiting_hold_cancellation.defined && waiting_hold_cancellation != '' ) %] + [% IF ( waiting_hold_cancellation != '' && waiting_hold_cancellation != 'undef' ) %] [% IF c == '*' %] @@ -971,13 +971,13 @@ [% NEXT UNLESS c %] [% SET open_article_requests_limit = CirculationRules.Search( branchcode, c, undef, 'open_article_requests_limit' ) %] - [% IF ( open_article_requests_limit.defined && open_article_requests_limit != '' ) %] + [% IF ( open_article_requests_limit != '' && open_article_requests_limit != 'undef' ) %] [% Categories.GetName(c) | html %] - [% IF open_article_requests_limit.defined && open_article_requests_limit != '' %] + [% IF open_article_requests_limit != '' && open_article_requests_limit != 'undef' %] [% open_article_requests_limit | html %] [% ELSE %] Unlimited -- 2.25.1