From c5cae7f648b2269efdafa4d28b1a3283df72c12f Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 2 Apr 2019 15:36:17 +0100 Subject: [PATCH] Bug 22563: Clean up remaining L cases --- .../data/mysql/atomicupdate/bug_22563.perl | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/installer/data/mysql/atomicupdate/bug_22563.perl b/installer/data/mysql/atomicupdate/bug_22563.perl index fd085b56a3..5187cf685a 100644 --- a/installer/data/mysql/atomicupdate/bug_22563.perl +++ b/installer/data/mysql/atomicupdate/bug_22563.perl @@ -1,6 +1,7 @@ $DBversion = 'XXX'; # will be replaced by the RM if ( CheckVersion($DBversion) ) { + # Find and correct pathological cases of LR my $sth = $dbh->prepare( "SELECT accountlines_id, issue_id, borrowernumber, itemnumber, amount, manager_id FROM accountlines WHERE accounttype = 'LR' AND amount < 0" ); $sth->execute(); while ( my $row = $sth->fetchrow_hashref ) { @@ -29,6 +30,47 @@ if ( CheckVersion($DBversion) ) { accounttype = 'LR'; }); + # Find and correct pathalogical cases of L having been converted to W + $sth = $dbh->prepare( "SELECT accountlines_id, issue_id, borrowernumber, itemnumber, amount, manager_id FROM accountlines WHERE accounttype = 'W' AND itemnumber IS NOT NULL" ); + $sth->execute(); + while ( my $row = $sth->fetchrow_hashref ) { + my $amount = $row->{amount} * -1; + $dbh->do( +"INSERT INTO accountlines (accounttype, status, issue_id, borrowernumber, itemnumber, amount, manager_id) VALUES ( ?, ?, ?, ?, ?, ? );", + {}, + ( + 'LOST', 'WAIVERED', $row->{issue_id}, $row->{borrowernumber}, + $row->{itemnumber}, $amount, $row->{manager_id} + ) + ); + my $debit_id = $dbh->last_insert_id(); + $dbh->do("INSERT INTO account_offsets (credit_id, debit_id, type, amount) VALUES (?,?,?,?);",{},($row->{accountlines_id}, $debit_id, 'Lost Item Returned', $amount)); + } + + $dbh->do(qq{ + UPDATE + accountlines + SET + accounttype = 'LOST', + status = 'UNRETURNED' + WHERE + accounttype = 'L' + AND + amountoutstanding > 0; + }); + + $dbh->do(qq{ + UPDATE + accountlines + SET + accounttype = 'LOST', + status = 'PAID' + WHERE + accounttype = 'L' + AND + amountoutstanding = 0; + }); + SetVersion($DBversion); - print "Upgrade to $DBversion done (Bug 22518 - Fix accounttypes for 'L' and 'LR')\n"; + print "Upgrade to $DBversion done (Bug 22563 - Fix accounttypes for 'L' and 'LR')\n"; } -- 2.20.1