[Koha-patches] [PATCH 1/2] [SIGNED-OFF] Bug #6064 Improvement of default value usage in overdue

Stéphane Delaune stephane.delaune at biblibre.com
Thu Apr 7 10:21:16 CEST 2011


From: Sophie Meynieux <sophie.meynieux at biblibre.com>

Change default value in overduerules table for delayn (NULL instead of 0) and fix GetBranchcodesWithOverdueRules function

Signed-off-by: Stéphane Delaune <stephane.delaune at biblibre.com>
---
 C4/Overdues.pm                         |    6 +++++-
 installer/data/mysql/kohastructure.sql |    6 +++---
 installer/data/mysql/updatedatabase.pl |    7 +++++++
 tools/overduerules.pl                  |    6 +++---
 4 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/C4/Overdues.pm b/C4/Overdues.pm
index a9af9d6..28b135c 100644
--- a/C4/Overdues.pm
+++ b/C4/Overdues.pm
@@ -957,9 +957,13 @@ returns a list of branch codes for branches with overdue rules defined.
 
 sub GetBranchcodesWithOverdueRules {
     my $dbh               = C4::Context->dbh;
-    my $rqoverduebranches = $dbh->prepare("SELECT DISTINCT branchcode FROM overduerules WHERE delay1 IS NOT NULL AND branchcode <> ''");
+    my $rqoverduebranches = $dbh->prepare("SELECT DISTINCT branchcode FROM overduerules WHERE delay1 IS NOT NULL AND branchcode <> '' ORDER BY branchcode");
     $rqoverduebranches->execute;
     my @branches = map { shift @$_ } @{ $rqoverduebranches->fetchall_arrayref };
+    if (!$branches[0]) {
+       my $availbranches = C4::Branch::GetBranches();
+       @branches = keys %$availbranches;
+    }
     return @branches;
 }
 
diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql
index 43ecf12..28dd5a6 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -1407,13 +1407,13 @@ DROP TABLE IF EXISTS `overduerules`;
 CREATE TABLE `overduerules` (
   `branchcode` varchar(10) NOT NULL default '',
   `categorycode` varchar(10) NOT NULL default '',
-  `delay1` int(4) default 0,
+  `delay1` int(4) default NULL,
   `letter1` varchar(20) default NULL,
   `debarred1` varchar(1) default 0,
-  `delay2` int(4) default 0,
+  `delay2` int(4) default NULL,
   `debarred2` varchar(1) default 0,
   `letter2` varchar(20) default NULL,
-  `delay3` int(4) default 0,
+  `delay3` int(4) default NULL,
   `letter3` varchar(20) default NULL,
   `debarred3` int(1) default 0,
   PRIMARY KEY  (`branchcode`,`categorycode`)
diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index 4e4aead..7f76078 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -4252,6 +4252,13 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     SetVersion ($DBversion);
 }
 
+$DBversion = "3.03.00.046";
+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+    $dbh->do("ALTER TABLE overduerules ALTER delay1 SET DEFAULT NULL, ALTER delay2 SET DEFAULT NULL, ALTER delay3 SET DEFAULT NULL");
+    print "Upgrade to $DBversion done (Setting NULL default value for delayn columns in table overduerules)\n";
+    SetVersion($DBversion);
+}
+
 =head1 FUNCTIONS
 
 =head2 DropAllForeignKeys($table)
diff --git a/tools/overduerules.pl b/tools/overduerules.pl
index 22822c5..478a762 100755
--- a/tools/overduerules.pl
+++ b/tools/overduerules.pl
@@ -142,13 +142,13 @@ if ($op eq 'save') {
                     my $res = $sth_search->fetchrow_hashref();
                     if ($res->{'total'}>0) {
                         $sth_update->execute(
-                            ($temphash{$bor}->{"delay1"}?$temphash{$bor}->{"delay1"}:0),
+                            ($temphash{$bor}->{"delay1"}?$temphash{$bor}->{"delay1"}:undef),
                             ($temphash{$bor}->{"letter1"}?$temphash{$bor}->{"letter1"}:""),
                             ($temphash{$bor}->{"debarred1"}?$temphash{$bor}->{"debarred1"}:0),
-                            ($temphash{$bor}->{"delay2"}?$temphash{$bor}->{"delay2"}:0),
+                            ($temphash{$bor}->{"delay2"}?$temphash{$bor}->{"delay2"}:undef),
                             ($temphash{$bor}->{"letter2"}?$temphash{$bor}->{"letter2"}:""),
                             ($temphash{$bor}->{"debarred2"}?$temphash{$bor}->{"debarred2"}:0),
-                            ($temphash{$bor}->{"delay3"}?$temphash{$bor}->{"delay3"}:0),
+                            ($temphash{$bor}->{"delay3"}?$temphash{$bor}->{"delay3"}:undef),
                             ($temphash{$bor}->{"letter3"}?$temphash{$bor}->{"letter3"}:""),
                             ($temphash{$bor}->{"debarred3"}?$temphash{$bor}->{"debarred3"}:0),
                             $branch ,$bor
-- 
1.7.0.4



More information about the Koha-patches mailing list