From d632fe1658a87c9e890db9aebd6e501260ae932b Mon Sep 17 00:00:00 2001 From: Jesse Weaver Date: Mon, 29 Jan 2018 15:30:29 -0700 Subject: [PATCH] Bug 18925: (follow-up) Fix null/empty behavior --- C4/Circulation.pm | 4 +-- admin/smart-rules.pl | 8 +++--- installer/data/mysql/atomicupdate/bug_18925.perl | 30 ++++++---------------- .../prog/en/modules/admin/smart-rules.tt | 4 +-- 4 files changed, 16 insertions(+), 30 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 4e98ffcaf4..c674561276 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -504,7 +504,7 @@ sub TooMany { # Now count total loans against the limit for the branch my $branch_borrower_circ_rule = GetBranchBorrowerCircRule($branch, $cat_borrower); - if (defined($branch_borrower_circ_rule->{patron_maxissueqty})) { + if (defined($branch_borrower_circ_rule->{patron_maxissueqty}) and $branch_borrower_circ_rule->{patron_maxissueqty} ne '') { my @bind_params = (); my $branch_count_query = q| SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts @@ -527,7 +527,7 @@ sub TooMany { my $max_checkouts_allowed = $branch_borrower_circ_rule->{patron_maxissueqty}; my $max_onsite_checkouts_allowed = $branch_borrower_circ_rule->{patron_maxonsiteissueqty}; - if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) { + if ( $onsite_checkout and $max_onsite_checkouts_allowed ne '' ) { if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed ) { return { reason => 'TOO_MANY_ONSITE_CHECKOUTS', diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index fbdbd8617d..e9c1bf121d 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -244,9 +244,9 @@ elsif ($op eq "set-branch-defaults") { my $returnbranch = $input->param('returnbranch'); my $max_holds = $input->param('max_holds'); $patron_maxissueqty =~ s/\s//g; - $patron_maxissueqty = undef if $patron_maxissueqty !~ /^\d+/; + $patron_maxissueqty = '' if $patron_maxissueqty !~ /^\d+/; $patron_maxonsiteissueqty =~ s/\s//g; - $patron_maxonsiteissueqty = undef if $patron_maxonsiteissueqty !~ /^\d+/; + $patron_maxonsiteissueqty = '' if $patron_maxonsiteissueqty !~ /^\d+/; $holdallowed =~ s/\s//g; $holdallowed = undef if $holdallowed !~ /^\d+/; $max_holds =~ s/\s//g; @@ -326,9 +326,9 @@ elsif ($op eq "add-branch-cat") { my $patron_maxonsiteissueqty = $input->param('patron_maxonsiteissueqty'); my $max_holds = $input->param('max_holds'); $patron_maxissueqty =~ s/\s//g; - $patron_maxissueqty = undef if $patron_maxissueqty !~ /^\d+/; + $patron_maxissueqty = '' if $patron_maxissueqty !~ /^\d+/; $patron_maxonsiteissueqty =~ s/\s//g; - $patron_maxonsiteissueqty = undef if $patron_maxonsiteissueqty !~ /^\d+/; + $patron_maxonsiteissueqty = '' if $patron_maxonsiteissueqty !~ /^\d+/; $max_holds =~ s/\s//g; $max_holds = undef if $max_holds !~ /^\d+/; diff --git a/installer/data/mysql/atomicupdate/bug_18925.perl b/installer/data/mysql/atomicupdate/bug_18925.perl index cafd0af504..3e5075fbe5 100644 --- a/installer/data/mysql/atomicupdate/bug_18925.perl +++ b/installer/data/mysql/atomicupdate/bug_18925.perl @@ -3,12 +3,12 @@ if( CheckVersion( $DBversion ) ) { if ( column_exists( 'branch_borrower_circ_rules', 'maxissueqty' ) ) { $dbh->do(" INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) - SELECT categorycode, branchcode, NULL, 'patron_maxissueqty', maxissueqty + SELECT categorycode, branchcode, NULL, 'patron_maxissueqty', COALESCE( maxissueqty, '' ) FROM branch_borrower_circ_rules "); $dbh->do(" INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) - SELECT categorycode, branchcode, NULL, 'patron_maxonsiteissueqty', maxonsiteissueqty + SELECT categorycode, branchcode, NULL, 'patron_maxonsiteissueqty', COALESCE( maxonsiteissueqty, '' ) FROM branch_borrower_circ_rules "); $dbh->do("DROP TABLE branch_borrower_circ_rules"); @@ -17,12 +17,12 @@ if( CheckVersion( $DBversion ) ) { if ( column_exists( 'default_borrower_circ_rules', 'maxissueqty' ) ) { $dbh->do(" INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) - SELECT categorycode, NULL, NULL, 'patron_maxissueqty', maxissueqty + SELECT categorycode, NULL, NULL, 'patron_maxissueqty', COALESCE( maxissueqty, '' ) FROM default_borrower_circ_rules "); $dbh->do(" INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) - SELECT categorycode, NULL, NULL, 'patron_maxonsiteissueqty', maxonsiteissueqty + SELECT categorycode, NULL, NULL, 'patron_maxonsiteissueqty', COALESCE( maxonsiteissueqty, '' ) FROM default_borrower_circ_rules "); $dbh->do("DROP TABLE default_borrower_circ_rules"); @@ -31,12 +31,12 @@ if( CheckVersion( $DBversion ) ) { if ( column_exists( 'default_circ_rules', 'maxissueqty' ) ) { $dbh->do(" INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) - SELECT NULL, NULL, NULL, 'patron_maxissueqty', maxissueqty + SELECT NULL, NULL, NULL, 'patron_maxissueqty', COALESCE( maxissueqty, '' ) FROM default_circ_rules "); $dbh->do(" INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) - SELECT NULL, NULL, NULL, 'patron_maxonsiteissueqty', maxonsiteissueqty + SELECT NULL, NULL, NULL, 'patron_maxonsiteissueqty', COALESCE( maxonsiteissueqty, '' ) FROM default_circ_rules "); $dbh->do("ALTER TABLE default_circ_rules DROP COLUMN maxissueqty, DROP COLUMN maxonsiteissueqty"); @@ -45,31 +45,17 @@ if( CheckVersion( $DBversion ) ) { if ( column_exists( 'default_branch_circ_rules', 'maxissueqty' ) ) { $dbh->do(" INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) - SELECT NULL, branchcode, NULL, 'patron_maxissueqty', maxissueqty + SELECT NULL, branchcode, NULL, 'patron_maxissueqty', COALESCE( maxissueqty, '' ) FROM default_branch_circ_rules "); $dbh->do(" INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) - SELECT NULL, NULL, NULL, 'patron_maxonsiteissueqty', maxonsiteissueqty + SELECT NULL, NULL, NULL, 'patron_maxonsiteissueqty', COALESCE( maxonsiteissueqty, '' ) FROM default_branch_circ_rules "); $dbh->do("ALTER TABLE default_branch_circ_rules DROP COLUMN maxissueqty, DROP COLUMN maxonsiteissueqty"); } - if ( column_exists( 'issuingrules', 'maxissueqty' ) ) { - $dbh->do(" - INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) - SELECT categorycode, branchcode, itemtype, 'maxissueqty', maxissueqty - FROM issuingrules - "); - $dbh->do(" - INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) - SELECT categorycode, branchcode, itemtype, 'maxonsiteissueqty', maxonsiteissueqty - FROM issuingrules - "); - $dbh->do("ALTER TABLE issuingrules DROP COLUMN maxissueqty, DROP COLUMN maxonsiteissueqty"); - } - SetVersion( $DBversion ); print "Upgrade to $DBversion done (Bug 18925 - Move maxissueqty and maxonsiteissueqty to circulation_rules)\n"; } 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 bac378953d..154c024052 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 @@ -547,14 +547,14 @@ [% END %] - [% IF patron_maxissueqty %] + [% IF patron_maxissueqty.defined && patron_maxissueqty != '' %] [% patron_maxissueqty | html %] [% ELSE %] Unlimited [% END %] - [% IF patron_maxonsiteissueqty %] + [% IF patron_maxonsiteissueqty.defined && patron_maxonsiteissueqty != '' %] [% patron_maxonsiteissueqty | html %] [% ELSE %] Unlimited -- 2.11.0