From fa06ad37b12ac990075f66a1cc8859d79f4aa207 Mon Sep 17 00:00:00 2001 From: Petro Vashchuk Date: Thu, 29 Sep 2022 14:38:45 +0300 Subject: [PATCH] Bug 25711: (QA follow-up) Remove leftover code and fix atomic update This patch finalizes another one which deprecates ExpireReservesMaxPickUpDelayCharge. Because we had multiple smart-rules with undefined "expire_reserves_charge" values, this patch updates actomic update to set not only the general All/All smart-rule row to deprecated ExpireReservesMaxPickUpDelayCharge value but also every smart-rule that fall back to default value in "expire_reserves_charge". Also removed additional leftovers in template which earlier expected to show hyperlink to syspref ExpireReservesMaxPickUpDelay. To check if atomic update functions correctly: 1) Go to syspref and set ExpireReservesMaxPickUpDelay as "allow", set ExpireReservesMaxPickUpDelayCharge to some numerical value (that will be your default value), for example "42". 2) Go to smart rules page and create three rules: a rule with empty "Expire reserve charge" value, then create another one rule with "Expire reserve charge" vaue "0", and then another rule with "Expire reserve charge" value set to any number, for example "12". 3) Apply the patch, and run the atomic update via the installer page. 4) Return to the smart rules page and check those rules you created in step 2: - That one rule that you set as empty, now should have "Expire reserve charge" equal 42, i.e. that one you set to the value you set ExpireReservesMaxPickUpDelayCharge in step 1. - All rules that had numerical values set previously should have been exist untouched. --- admin/smart-rules.pl | 2 +- .../data/mysql/atomicupdate/bug_25711.pl | 47 ++++++++++++++++--- .../prog/en/modules/admin/smart-rules.tt | 6 +-- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index 38d8b7e6c9..8baebb52ef 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -291,7 +291,7 @@ elsif ($op eq 'add') { my $overduefinescap = $input->param('overduefinescap') && ( $input->param('overduefinescap') + 0 ) > 0 ? sprintf( "%.02f", $input->param('overduefinescap') ) : q{}; my $cap_fine_to_replacement_price = ($input->param('cap_fine_to_replacement_price') || q{}) eq 'on'; - my $expire_reserves_charge = $input->param('expire_reserves_charge') // q{}; + my $expire_reserves_charge = $input->param('expire_reserves_charge') || 0; my $note = $input->param('note'); my $decreaseloanholds = $input->param('decreaseloanholds') || q{}; my $recalls_allowed = $input->param('recalls_allowed'); diff --git a/installer/data/mysql/atomicupdate/bug_25711.pl b/installer/data/mysql/atomicupdate/bug_25711.pl index 10e682c4d4..30799ccdd0 100755 --- a/installer/data/mysql/atomicupdate/bug_25711.pl +++ b/installer/data/mysql/atomicupdate/bug_25711.pl @@ -12,14 +12,47 @@ return { WHERE variable='ExpireReservesMaxPickUpDelayCharge'; }); - $expire_reserves_charge //= 0; + $expire_reserves_charge ||= 0; - $dbh->do(qq{ - INSERT INTO circulation_rules - ( categorycode, branchcode, itemtype, rule_name, rule_value ) - VALUES - ( NULL, NULL, NULL, 'expire_reserves_charge', $expire_reserves_charge ); - }); + my $sth = $dbh->prepare("SELECT branchcode, categorycode, itemtype FROM circulation_rules + GROUP BY branchcode, categorycode, itemtype"); + $sth->execute(); + + while ( my $r = $sth->fetchrow_hashref ) { + my ($expire_reserves_charge_value) = $dbh->do(" + DELETE FROM circulation_rules + WHERE + categorycode ".(defined $r->{categorycode} ? "= '$r->{categorycode}'" : 'IS NULL')." + AND branchcode ".(defined $r->{branchcode} ? "= '$r->{branchcode}'" : 'IS NULL')." + AND itemtype ".(defined $r->{itemtype} ? "= '$r->{itemtype}'" : 'IS NULL')." + AND rule_name = 'expire_reserves_charge' + AND (rule_value IS NULL OR rule_value = '') + "); + + my ($expire_reserves_charge_value_exists) = $dbh->selectrow_array(" + SELECT COUNT(1) FROM circulation_rules + WHERE + categorycode ".(defined $r->{categorycode} ? "= '$r->{categorycode}'" : 'IS NULL')." + AND branchcode ".(defined $r->{branchcode} ? "= '$r->{branchcode}'" : 'IS NULL')." + AND itemtype ".(defined $r->{itemtype} ? "= '$r->{itemtype}'" : 'IS NULL')." + AND rule_name = 'expire_reserves_charge' + "); + + if( ! $expire_reserves_charge_value_exists ) { + $dbh->do(qq{ + INSERT INTO circulation_rules + ( categorycode, branchcode, itemtype, rule_name, rule_value ) + VALUES + ( } + .(defined $r->{categorycode} ? "'$r->{categorycode}'" : 'NULL') + ."," + .(defined $r->{branchcode} ? "'$r->{branchcode}'" : 'NULL') + ."," + .(defined $r->{itemtype} ? "'$r->{itemtype}'" : 'NULL') + .qq{, 'expire_reserves_charge', $expire_reserves_charge ); + }); + } + } say $out "ExpireReservesMaxPickUpDelayCharge migrated to the expire_reserves_charge circulation rule"; }, 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 884688b234..3a4c092946 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 @@ -309,11 +309,7 @@ [% END %] - [% IF expire_reserves_charge.defined && expire_reserves_charge != '' %] - [% expire_reserves_charge | html %] - [% ELSE %] - Default - [% END %] + [% expire_reserves_charge | html %] [% finedays | html %] [% maxsuspensiondays | html %] -- 2.42.0