From 321d37f659513376a6e722c73691e19a180adcbf Mon Sep 17 00:00:00 2001 From: Arthur Suzuki Date: Fri, 14 Oct 2022 21:47:44 +0200 Subject: [PATCH] Revert Bug 29012: Some rules are not saved when left blank while editing a 'rule' line in smart-rules.pl Signed-off-by: Arthur Suzuki --- C4/Circulation.pm | 4 +-- admin/smart-rules.pl | 30 ++++++++--------- installer/data/mysql/db_revs/211112001.pl | 33 ------------------- installer/onboarding.pl | 3 +- .../prog/en/modules/admin/smart-rules.tt | 8 +---- 5 files changed, 20 insertions(+), 58 deletions(-) delete mode 100755 installer/data/mysql/db_revs/211112001.pl diff --git a/C4/Circulation.pm b/C4/Circulation.pm index fd1c9b5f9d..1b05aab76a 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2782,7 +2782,7 @@ sub CanBookBeRenewed { return ( 0, "too_unseen" ) if C4::Context->preference('UnseenRenewals') && - looks_like_number($issuing_rule->{unseen_renewals_allowed}) && + $issuing_rule->{unseen_renewals_allowed} && $issuing_rule->{unseen_renewals_allowed} <= $issue->unseen_renewals; my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing'); @@ -3008,7 +3008,7 @@ sub AddRenewal { rule_name => 'unseen_renewals_allowed' } ); - if (!$seen && $rule && looks_like_number($rule->rule_value)) { + if (!$seen && $rule && $rule->rule_value) { $unseen_renewals++; } else { # If the renewal is seen, unseen should revert to 0 diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index f4762bf2aa..31ed87a83a 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -250,7 +250,7 @@ elsif ($op eq 'add') { my $itemtype = $input->param('itemtype'); # item type my $fine = $input->param('fine'); my $finedays = $input->param('finedays'); - my $maxsuspensiondays = $input->param('maxsuspensiondays') || q{}; + my $maxsuspensiondays = $input->param('maxsuspensiondays') || ''; my $suspension_chargeperiod = $input->param('suspension_chargeperiod') || 1; my $firstremind = $input->param('firstremind'); my $chargeperiod = $input->param('chargeperiod'); @@ -258,34 +258,35 @@ elsif ($op eq 'add') { my $maxissueqty = strip_non_numeric( scalar $input->param('maxissueqty') ); my $maxonsiteissueqty = strip_non_numeric( scalar $input->param('maxonsiteissueqty') ); my $renewalsallowed = $input->param('renewalsallowed'); - my $unseen_renewals_allowed = strip_non_numeric( scalar $input->param('unseen_renewals_allowed') ) // q{}; + my $unseen_renewals_allowed = $input->param('unseen_renewals_allowed'); my $renewalperiod = $input->param('renewalperiod'); my $norenewalbefore = $input->param('norenewalbefore'); - $norenewalbefore = q{} if $norenewalbefore =~ /^\s*$/; + $norenewalbefore = '' if $norenewalbefore =~ /^\s*$/; my $auto_renew = $input->param('auto_renew') eq 'yes' ? 1 : 0; my $no_auto_renewal_after = $input->param('no_auto_renewal_after'); - $no_auto_renewal_after = q{} if $no_auto_renewal_after =~ /^\s*$/; - my $no_auto_renewal_after_hard_limit = $input->param('no_auto_renewal_after_hard_limit') || q{}; + $no_auto_renewal_after = '' if $no_auto_renewal_after =~ /^\s*$/; + my $no_auto_renewal_after_hard_limit = $input->param('no_auto_renewal_after_hard_limit') || ''; $no_auto_renewal_after_hard_limit = eval { dt_from_string( scalar $no_auto_renewal_after_hard_limit ) } if ( $no_auto_renewal_after_hard_limit ); $no_auto_renewal_after_hard_limit = output_pref( { dt => $no_auto_renewal_after_hard_limit, dateonly => 1, dateformat => 'iso' } ) if ( $no_auto_renewal_after_hard_limit ); my $reservesallowed = strip_non_numeric( scalar $input->param('reservesallowed') ); my $holds_per_record = strip_non_numeric( scalar $input->param('holds_per_record') ); my $holds_per_day = strip_non_numeric( scalar $input->param('holds_per_day') ); my $onshelfholds = $input->param('onshelfholds') || 0; - my $issuelength = $input->param('issuelength') || 0; + my $issuelength = $input->param('issuelength'); + $issuelength = $issuelength eq q{} ? undef : $issuelength; my $daysmode = $input->param('daysmode'); my $lengthunit = $input->param('lengthunit'); - my $hardduedate = $input->param('hardduedate') || q{}; + my $hardduedate = $input->param('hardduedate') || undef; $hardduedate = eval { dt_from_string( scalar $hardduedate ) } if ( $hardduedate ); $hardduedate = output_pref( { dt => $hardduedate, dateonly => 1, dateformat => 'iso' } ) if ( $hardduedate ); my $hardduedatecompare = $input->param('hardduedatecompare'); - my $rentaldiscount = $input->param('rentaldiscount') || 0; + my $rentaldiscount = $input->param('rentaldiscount'); my $opacitemholds = $input->param('opacitemholds') || 0; my $article_requests = $input->param('article_requests') || 'no'; - my $overduefinescap = $input->param('overduefinescap') || q{}; - my $cap_fine_to_replacement_price = ($input->param('cap_fine_to_replacement_price') || q{}) eq 'on'; + my $overduefinescap = $input->param('overduefinescap') || ''; + my $cap_fine_to_replacement_price = ($input->param('cap_fine_to_replacement_price') || '') eq 'on'; my $note = $input->param('note'); - my $decreaseloanholds = $input->param('decreaseloanholds') || q{}; + my $decreaseloanholds = $input->param('decreaseloanholds') || undef; my $rules = { maxissueqty => $maxissueqty, @@ -463,7 +464,7 @@ elsif ( $op eq "add-open-article-requests-limit" ) { Koha::Exceptions::Exception->throw("No value passed for article request limit") if not defined $open_article_requests_limit # There is a JS check for that - || $open_article_requests_limit eq q{}; + || $open_article_requests_limit eq ''; if ( $branch eq "*" ) { if ( $categorycode eq "*" ) { @@ -530,7 +531,6 @@ elsif ( $op eq "add-open-article-requests-limit" ) { ); } } - elsif ($op eq "add-branch-item") { my $itemtype = $input->param('itemtype'); my $holdallowed = $input->param('holdallowed'); @@ -636,7 +636,7 @@ my $definedbranch = $all_rules->count ? 1 : 0; my $rules = {}; while ( my $r = $all_rules->next ) { $r = $r->unblessed; - $rules->{ $r->{categorycode} // q{} }->{ $r->{itemtype} // q{} }->{ $r->{rule_name} } = $r->{rule_value}; + $rules->{ $r->{categorycode} // '' }->{ $r->{itemtype} // '' }->{ $r->{rule_name} } = $r->{rule_value}; } $template->param(show_branch_cat_rule_form => 1); @@ -686,6 +686,6 @@ sub by_itemtype { sub strip_non_numeric { my $string = shift; $string =~ s/\s//g; - $string = q{} if $string !~ /^\d+/; + $string = '' if $string !~ /^\d+/; return $string; } diff --git a/installer/data/mysql/db_revs/211112001.pl b/installer/data/mysql/db_revs/211112001.pl deleted file mode 100755 index 26aac4b686..0000000000 --- a/installer/data/mysql/db_revs/211112001.pl +++ /dev/null @@ -1,33 +0,0 @@ -use Modern::Perl; - -return { - bug_number => "29012", - description => "Some rules are not saved when left blank while editing a 'rule' line in smart-rules.pl", - up => sub { - my ($args) = @_; - my ($dbh, $out) = @$args{qw(dbh out)}; - my %default_rule_values = ( - issuelength => 0, - hardduedate => '', - unseenrenewalsallowed => '', - rentaldiscount => 0, - decreaseloanholds => '', - ); - while (my ($rule_name, $rule_value) = each (%default_rule_values)) { - $dbh->do(q{ - INSERT IGNORE INTO circulation_rules (branchcode, categorycode, itemtype, rule_name, rule_value) - SELECT branchcode, categorycode, itemtype, ?, ? FROM circulation_rules cr - WHERE NOT EXISTS ( - SELECT * FROM circulation_rules cr2 - WHERE - cr2.rule_name=? - AND ( (cr2.branchcode=cr.branchcode) OR ( ISNULL(cr2.branchcode) AND ISNULL(cr.branchcode) ) ) - AND ( (cr2.categorycode=cr.categorycode) OR ( ISNULL(cr2.categorycode) AND ISNULL(cr.categorycode) ) ) - AND ( (cr2.itemtype=cr.itemtype) OR ( ISNULL(cr2.itemtype) AND ISNULL(cr.itemtype) ) ) - ) - GROUP BY branchcode, categorycode, itemtype - }, undef, $rule_name, $rule_value, $rule_name); - } - say $out "Add default values for blank circulation rules that weren't saved to the database"; - }, -} diff --git a/installer/onboarding.pl b/installer/onboarding.pl index 2b19902f86..727bc93eea 100755 --- a/installer/onboarding.pl +++ b/installer/onboarding.pl @@ -242,7 +242,7 @@ if ( $step == 5 ) { my $categorycode = $input->param('categorycode'); my $itemtype = $input->param('itemtype'); my $maxissueqty = $input->param('maxissueqty'); - my $issuelength = $input->param('issuelength') || 0; + my $issuelength = $input->param('issuelength'); my $lengthunit = $input->param('lengthunit'); my $renewalsallowed = $input->param('renewalsallowed'); my $renewalperiod = $input->param('renewalperiod'); @@ -252,6 +252,7 @@ if ( $step == 5 ) { my $onshelfholds = $input->param('onshelfholds') || 0; $maxissueqty =~ s/\s//g; $maxissueqty = undef if $maxissueqty !~ /^\d+/; + $issuelength = $issuelength eq q{} ? undef : $issuelength; my $params = { branchcode => $branchcode, 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 e92147c5b5..b0b61bcf6d 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 @@ -283,13 +283,7 @@ [% suspension_chargeperiod | html %] [% renewalsallowed | html %] [% IF Koha.Preference('UnseenRenewals') %] - - [% IF unseenrenewalsallowed.defined && unseenrenewalsallowed != '' %] - [% unseenrenewalsallowed | html %] - [% ELSE %] - Unlimited - [% END %] - + [% unseenrenewalsallowed | html %] [% END %] [% renewalperiod | html %] [% norenewalbefore | html %] -- 2.39.5