Bug 18925: (follow-up) Fix null/empty behavior
authorJesse Weaver <pianohacker@gmail.com>
Mon, 29 Jan 2018 22:30:29 +0000 (15:30 -0700)
committerNick Clemens <nick@bywatersolutions.com>
Tue, 5 Mar 2019 20:41:42 +0000 (20:41 +0000)
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

C4/Circulation.pm
admin/smart-rules.pl
installer/data/mysql/atomicupdate/bug_18925.perl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt

index 658286e..f4bdbf4 100644 (file)
@@ -505,7 +505,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
@@ -528,7 +528,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',
index fbdbd86..e9c1bf1 100755 (executable)
@@ -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+/;
 
index cafd0af..3e5075f 100644 (file)
@@ -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";
 }
index e26dbcd..8f0bf83 100644 (file)
                             [% END %]
                         </td>
                         <td>
-                            [% IF patron_maxissueqty  %]
+                            [% IF patron_maxissueqty.defined && patron_maxissueqty != '' %]
                                 [% patron_maxissueqty | html %]
                             [% ELSE %]
                                 <span>Unlimited</span>
                             [% END %]
                         </td>
                         <td>
-                            [% IF patron_maxonsiteissueqty  %]
+                            [% IF patron_maxonsiteissueqty.defined && patron_maxonsiteissueqty != '' %]
                                 [% patron_maxonsiteissueqty | html %]
                             [% ELSE %]
                                 <span>Unlimited</span>