From 92bf8082c372d4cf055336da7539bf214847249f Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 11 Jul 2019 16:29:48 +0100 Subject: [PATCH] Bug 22563: DBRev 19.06.00.012 Signed-off-by: Martin Renvoize --- Koha.pm | 2 +- .../data/mysql/atomicupdate/bug_22563.perl | 70 ---------------- installer/data/mysql/updatedatabase.pl | 80 +++++++++++++++++++ 3 files changed, 81 insertions(+), 71 deletions(-) delete mode 100644 installer/data/mysql/atomicupdate/bug_22563.perl diff --git a/Koha.pm b/Koha.pm index 8c74a9059a..04feee3754 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 = "19.06.00.011"; +$VERSION = "19.06.00.012"; sub version { return $VERSION; diff --git a/installer/data/mysql/atomicupdate/bug_22563.perl b/installer/data/mysql/atomicupdate/bug_22563.perl deleted file mode 100644 index e8176f7c6b..0000000000 --- a/installer/data/mysql/atomicupdate/bug_22563.perl +++ /dev/null @@ -1,70 +0,0 @@ -$DBversion = 'XXX'; # will be replaced by the RM -if ( CheckVersion($DBversion) ) { - - # Find and correct pathological cases of LR becoming a credit - 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 ) { - $dbh->do( - "INSERT INTO accountlines (accounttype, issue_id, borrowernumber, itemnumber, amount, manager_id) VALUES ( ?, ?, ?, ?, ?, ? );", - {}, - ( - 'CR', $row->{issue_id}, - $row->{borrowernumber}, $row->{itemnumber}, - $row->{amount}, $row->{manager_id} - ) - ); - my $credit_id = $dbh->last_insert_id(); - my $amount = $row->{amount} * -1; - $dbh->do("INSERT INTO account_offsets (credit_id, debit_id, type, amount) VALUES (?,?,?,?);",{},($credit_id, $row->{accountlines_id}, 'Lost Item', $amount)); - $dbh->do("UPDATE accountlines SET amount = '$amount' WHERE accountlines_id = '$row->{accountlines_id}';"); - } - - $dbh->do(qq{ - UPDATE - accountlines - SET - accounttype = 'LOST', - status = 'RETURNED' - WHERE - 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, issue_id, borrowernumber, itemnumber, amount, manager_id) VALUES ( ?, ?, ?, ?, ?, ? );", - {}, - ( - 'LOST', $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' - WHERE - accounttype = 'L'; - }); - - $dbh->do(qq{ - UPDATE - accountlines - SET - accounttype = 'LOST_RETURNED' - WHERE - accounttype = 'CR'; - }); - - SetVersion($DBversion); - print "Upgrade to $DBversion done (Bug 22563 - Fix accounttypes for 'L', 'LR' and 'CR')\n"; -} diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 3289c3f609..01a47cb0d1 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -18899,6 +18899,86 @@ if( CheckVersion( $DBversion ) ) { print "Upgrade to $DBversion done (Bug 18930 - Move lost item refund rules to circulation_rules table)\n"; } +$DBversion = '19.06.00.012'; +if ( CheckVersion($DBversion) ) { + + # Find and correct pathological cases of LR becoming a credit + 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 ) { + $dbh->do( + "INSERT INTO accountlines (accounttype, issue_id, borrowernumber, itemnumber, amount, manager_id, interface) VALUES ( ?, ?, ?, ?, ?, ?, ? );", + {}, + ( + 'CR', $row->{issue_id}, + $row->{borrowernumber}, $row->{itemnumber}, + $row->{amount}, $row->{manager_id}, + 'upgrade' + ) + ); + my $credit_id = $dbh->last_insert_id(undef, undef, 'accountlines', undef); + my $amount = $row->{amount} * -1; + $dbh->do("INSERT INTO account_offsets (credit_id, debit_id, type, amount) VALUES (?,?,?,?);",{},($credit_id, $row->{accountlines_id}, 'Lost Item', $amount)); + $dbh->do("UPDATE accountlines SET amount = '$amount' WHERE accountlines_id = '$row->{accountlines_id}';"); + } + + $dbh->do(qq{ + UPDATE + accountlines + SET + accounttype = 'LOST', + status = 'RETURNED' + WHERE + 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, issue_id, borrowernumber, itemnumber, amount, manager_id, interface) VALUES ( ?, ?, ?, ?, ?, ?, ? );", + {}, + ( + 'LOST', $row->{issue_id}, $row->{borrowernumber}, + $row->{itemnumber}, $amount, $row->{manager_id}, + 'upgrade' + ) + ); + my $debit_id = $dbh->last_insert_id(undef, undef, 'accountlines', undef); + $dbh->do( + "INSERT INTO account_offsets (credit_id, debit_id, type, amount) VALUES (?,?,?,?);", + {}, + ( + $row->{accountlines_id}, $debit_id, + 'Lost Item', $amount + ) + ); + } + + $dbh->do(qq{ + UPDATE + accountlines + SET + accounttype = 'LOST' + WHERE + accounttype = 'L'; + }); + + $dbh->do(qq{ + UPDATE + accountlines + SET + accounttype = 'LOST_RETURNED' + WHERE + accounttype = 'CR'; + }); + + SetVersion($DBversion); + print "Upgrade to $DBversion done (Bug 22563 - Fix accounttypes for 'L', 'LR' and 'CR')\n"; +} + # SEE bug 13068 # if there is anything in the atomicupdate, read and execute it. my $update_dir = C4::Context->config('intranetdir') . '/installer/data/mysql/atomicupdate/'; -- 2.39.5