From 141a52ac30c94b0f5e8dde0d29552bc8d5f44553 Mon Sep 17 00:00:00 2001 From: Sophie Meynieux Date: Thu, 7 Apr 2011 10:21:16 +0200 Subject: [PATCH] Bug #6064 Improvement of default value usage in overdue MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change default value in overduerules table for delayn (NULL instead of 0) and fix GetBranchcodesWithOverdueRules function Signed-off-by: Stéphane Delaune Signed-off-by: Chris Cormack --- 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 a9af9d61e5..28b135c5a4 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 43ecf122c3..28dd5a60ae 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 4e4aeadb72..7f76078eed 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 22822c54b5..478a762e73 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 -- 2.39.5