@@ -, +, @@ 'return' rows --- installer/data/mysql/updatedatabase.pl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -39,6 +39,7 @@ use C4::Installer; use C4::Dates; use Koha::Database; use Koha; +use Koha::Items; use MARC::Record; use MARC::File::XML ( BinaryEncoding => 'utf8' ); @@ -10761,6 +10762,30 @@ if ( CheckVersion($DBversion) ) { SetVersion ($DBversion); } +$DBversion = "3.21.00.XXX"; +if ( CheckVersion($DBversion) ) { + # Fix return statistic itemtypes + my $stats = $schema->resultset('Statistic')->search({ + type => 'return', + itemtype => undef }); + + while ( my $stat = $stats->next() ) { + + my $itemnumber = $stat->itemnumber(); + my $itemtype = Koha::Items->find( $itemnumber )->effective_itemtype(); + + $sth = $dbh->prepare(q{ + UPDATE statistics + SET itemtype=? + WHERE type='return' AND itemnumber=? AND itemtype IS NULL + }); + $sth->execute( $itemtype, $itemnumber ); + } + + print "Upgrade to $DBversion done (Bug 14598: itemtype is not set on statistics by C4::Circulation::AddReturn)\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. --