From c0a077c96f25684bf9a2fd4bf7ef4836f4186817 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 5 Oct 2021 11:30:37 +0200 Subject: [PATCH] Bug 27945: Don't save rule if not defined The DB rev added a row with NULL (unlimited), and the UI a row with '' (unlimited as well) when saved without value. Better is to not have a row (still unlimited) --- admin/smart-rules.pl | 5 +++++ installer/data/mysql/atomicupdate/bug_27945.pl | 16 ---------------- .../prog/en/modules/admin/smart-rules.tt | 10 +++++++++- 3 files changed, 14 insertions(+), 17 deletions(-) delete mode 100755 installer/data/mysql/atomicupdate/bug_27945.pl diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index cc4370a44f6..171653a3d4c 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -22,6 +22,7 @@ use CGI qw ( -utf8 ); use C4::Context; use C4::Output qw( output_html_with_http_headers ); use C4::Auth qw( get_template_and_user ); +use Koha::Exceptions::Exception; use Koha::DateUtils qw( dt_from_string output_pref ); use Koha::Database; use Koha::Logger; @@ -461,6 +462,10 @@ elsif ( $op eq "add-max-daily-article-requests" ) { my $categorycode = $input->param('categorycode'); my $max_daily_article_requests = strip_non_numeric( scalar $input->param('max_daily_article_requests') ); + Koha::Exceptions::Exception->throw("No value passed for article request limit") + if not defined $max_daily_article_requests # There is a JS check for that + || $max_daily_article_requests eq ''; + if ( $branch eq "*" ) { if ( $categorycode eq "*" ) { Koha::CirculationRules->set_rules( diff --git a/installer/data/mysql/atomicupdate/bug_27945.pl b/installer/data/mysql/atomicupdate/bug_27945.pl deleted file mode 100755 index 2be48d80c95..00000000000 --- a/installer/data/mysql/atomicupdate/bug_27945.pl +++ /dev/null @@ -1,16 +0,0 @@ -use Modern::Perl; - -return { - bug_number => "27945", - description => "Add max_daily_article_requests circulation rule", - up => sub { - my ($args) = @_; - my ($dbh) = @$args{qw(dbh)}; - - # Do you stuffs here - $dbh->do(q{ - INSERT IGNORE INTO circulation_rules (branchcode, categorycode, itemtype, rule_name, rule_value) - VALUES (NULL, NULL, NULL, 'max_daily_article_requests', NULL); - }); - }, - } 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 209d44f34b6..a7497229fde 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 @@ -795,7 +795,7 @@

Default article requests limits

[% END %]

Specify the maximum number simultaneous current article requests a patron of a given category can have.

-
+ @@ -1229,6 +1229,14 @@ e.preventDefault(); clear_edit(); }); + + $("#set-article-requests-daily-limit").on("submit", function(){ + if (! $("input[name='max_daily_article_requests'").val().length){ + alert("Please set a daily limit for this patron's category"); + return false; + } + return true; + }); }); [% END %] -- 2.25.1