From 73808a1fd00740a5796c5e81b96be13294d482ad Mon Sep 17 00:00:00 2001 From: Brendan Gallagher Date: Wed, 2 Mar 2016 03:36:01 +0000 Subject: [PATCH] DBREV - Bug 15675 - Add issue_id column to accountlines and use it for updating fines Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com --- Koha.pm | 2 +- .../data/mysql/atomicupdate/bug_15334.sql | 21 ----------- installer/data/mysql/updatedatabase.pl | 36 +++++++++++++++++++ 3 files changed, 37 insertions(+), 22 deletions(-) delete mode 100644 installer/data/mysql/atomicupdate/bug_15334.sql diff --git a/Koha.pm b/Koha.pm index 92aa123d96..7aeb0e471e 100644 --- a/Koha.pm +++ b/Koha.pm @@ -29,7 +29,7 @@ use vars qw{ $VERSION }; # - #4 : the developer version. The 4th number is the database subversion. # used by developers when the database changes. updatedatabase take care of the changes itself # and is automatically called by Auth.pm when needed. -$VERSION = "3.23.00.031"; +$VERSION = "3.23.00.032"; sub version { return $VERSION; diff --git a/installer/data/mysql/atomicupdate/bug_15334.sql b/installer/data/mysql/atomicupdate/bug_15334.sql deleted file mode 100644 index 89aead4c3e..0000000000 --- a/installer/data/mysql/atomicupdate/bug_15334.sql +++ /dev/null @@ -1,21 +0,0 @@ --- Add issue_id to accountlines table -ALTER TABLE accountlines ADD issue_id INT(11) NULL DEFAULT NULL AFTER accountlines_id; - --- Close out any accruing fines with no current issue -UPDATE accountlines LEFT JOIN issues USING ( itemnumber, borrowernumber ) SET accounttype = 'F' WHERE accounttype = 'FU' and issues.issue_id IS NULL; - --- Close out any extra not really accruing fines, keep only the latest accring fine -UPDATE accountlines a1 - LEFT JOIN (SELECT MAX(accountlines_id) AS keeper, - borrowernumber, - itemnumber - FROM accountlines - WHERE accounttype = 'FU' - GROUP BY borrowernumber, itemnumber - ) a2 USING ( borrowernumber, itemnumber ) -SET a1.accounttype = 'F' -WHERE a1.accounttype = 'FU' - AND a1.accountlines_id != a2.keeper; - --- Update the unclosed fines to add the current issue_id to them -UPDATE accountlines LEFT JOIN issues USING ( itemnumber ) SET accountlines.issue_id = issues.issue_id WHERE accounttype = 'FU'; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 3f0629dec4..f81f7b3e41 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -11892,6 +11892,42 @@ if(CheckVersion($DBversion)) { SetVersion($DBversion); } +$DBversion = "3.23.00.032"; +if ( CheckVersion($DBversion) ) { + $dbh->do(q{ + -- Add issue_id to accountlines table + ALTER TABLE accountlines ADD issue_id INT(11) NULL DEFAULT NULL AFTER accountlines_id; + }); + +## Close out any accruing fines with no current issue + $dbh->do(q{ + UPDATE accountlines LEFT JOIN issues USING ( itemnumber, borrowernumber ) SET accounttype = 'F' WHERE accounttype = 'FU' and issues.issue_id IS NULL; + }); + +## Close out any extra not really accruing fines, keep only the latest accring fine + $dbh->do(q{ + UPDATE accountlines a1 + LEFT JOIN (SELECT MAX(accountlines_id) AS keeper, + borrowernumber, + itemnumber + FROM accountlines + WHERE accounttype = 'FU' + GROUP BY borrowernumber, itemnumber + ) a2 USING ( borrowernumber, itemnumber ) + SET a1.accounttype = 'F' + WHERE a1.accounttype = 'FU' + AND a1.accountlines_id != a2.keeper; + }); + +## Update the unclosed fines to add the current issue_id to them + $dbh->do(q{ + UPDATE accountlines LEFT JOIN issues USING ( itemnumber ) SET accountlines.issue_id = issues.issue_id WHERE accounttype = 'FU'; + }); + + print "Upgrade to $DBversion done (Bug 15675 - Add issue_id column to accountlines and use it for updating fines)\n"; + SetVersion($DBversion); +} + # DEVELOPER PROCESS, search for anything to execute in the db_update directory # SEE bug 13068 # if there is anything in the atomicupdate, read and execute it. -- 2.39.5