Bug 22511: (QA follow-up) Fix update database
[koha-equinox.git] / installer / data / mysql / atomicupdate / bug_22511.perl
1 $DBversion = 'XXX';    # will be replaced by the RM
2 if ( CheckVersion($DBversion) ) {
3
4     my $types_map = {
5         'Writeoff'      => 'W',
6         'Payment'       => 'Pay',
7         'List Item'     => 'CR',
8         'Manual Credit' => 'C',
9         'Forgiven'      => 'FOR'
10     };
11
12     my $sth = $dbh->prepare( "SELECT accountlines_id FROM accountlines WHERE accounttype = 'VOID'" );
13     my $sth2 = $dbh->prepare( "SELECT type FROM account_offsets WHERE credit_id = ? ORDER BY created_on LIMIT 1" );
14     my $sth3 = $dbh->prepare( "UPDATE accountlines SET accounttype = ?, status = 'VOID' WHERE accountlines_id = ?" );
15     $sth->execute();
16     while (my $row = $sth->fetchrow_hashref) {
17         $sth2->execute($row->{accountlines_id});
18         my $result = $sth2->fetchrow_hashref;
19         my $type = $types_map->{$result->{'type'}} // 'Pay';
20         $sth3->execute($type,$row->{accountlines_id});
21     }
22
23     SetVersion($DBversion);
24     print "Upgrade to $DBversion done (Bug 22511 - Update existing VOID accountlines)\n";
25 }