From 973680bf4cfb44d9f7f04053654a39b06e71b71d Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 18 Aug 2015 16:21:27 -0300 Subject: [PATCH] Bug 14598: (DB update) fix NULL itemtypes in statistics on 'return' rows This patch introduces an updatedatabase.pl block that updates the rows that lack itemtype. It relies on Koha::Item->effective_itemtype() to choose the rigt one. I wrote it using SQL because the statistics table lacks PKs. Note: I'm not sure about making this dependent on 14651, I need a QA POV on this, and I'm biased as I wrote all the related patches... --- installer/data/mysql/updatedatabase.pl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 10809a1..1e015f4 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/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. -- 2.5.0