From 53de9ba59389ceeabed1cdfb3e3736cbda100f48 Mon Sep 17 00:00:00 2001 From: Olli-Antti Kivilahti Date: Thu, 8 Jan 2015 20:26:40 +0200 Subject: [PATCH] Bug 13540 - Item's permanent_location is set to CART|PROC if an Item is edited when it's location is CART|PROC. This bug is rather nasty as it happens very discreetly when editing Items that are in either locations 'CART' or 'PROC'. For example when changing one of the Item's statuses or barcode, the permanent_location gets overwritten without the user noticing it immediately. The damage becomes apparent only weeks later when there are potentially thousands of Items missing the permanent_location and location. :-:TEST SETUP:-: 0a. System preference "ReturnToShelvingCart" must be 'Move'. 0b. Find any Item (I69) 0c. Set I69's location to "Book Cart" (BC) or anything but empty. :-:REPLICATE ISSUE:-: 1. Check-in the I69 and the location should turn to 'CART' (returned today). 2. Go to the "Edit Item"-view for I69, don't change anything, simply click "Save changes" 3. Observe that the permanent_location has changed to 'CART'. This is not good since now the location data is forever lost again (Bugg 7817). The "cart_to_shelf.pl --hours 24"-script cannot return the Item to the proper place ;( :-:AFTER THIS PATCH:-: Repeat steps 1-2. 3. Observe that the permanent_location is still the old one, instead of getting overwritten by 'CART'. Signed-off-by: Chris Cormack --- C4/Items.pm | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/C4/Items.pm b/C4/Items.pm index 33143a5..1dd7fe0 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -956,6 +956,22 @@ sub GetItemLocation { return \%itemlocation; } +=head GetRealItemLocations + + my $locations = C4::Items::GetRealItemLocations($itemnumber); + +A convenience function of getting just the Item location and permanent_location +@PARAM1, Long, the koha-items.itemnumber +@RETURNS, Reference to Hash, with koha.items.location and permanent_location as hash keys. + +=cut +sub GetRealItemLocations { + my $itemnumber = shift; + my $sth = C4::Context->dbh()->prepare('SELECT location, permanent_location FROM items WHERE itemnumber = ?'); + $sth->execute($itemnumber); + return $sth->fetchrow_hashref(); +} + =head2 GetLostItems $items = GetLostItems( $where, $orderby ); @@ -2030,7 +2046,15 @@ sub _do_column_fixes_for_mod { $item->{'withdrawn'} = 0; } if (exists $item->{'location'} && !$item->{'permanent_location'}) { - $item->{'permanent_location'} = $item->{'location'}; + if ($item->{'location'} ne 'CART' && $item->{'location'} ne 'PROC') { + $item->{'permanent_location'} = $item->{'location'}; + } + else { + #Preserve the old permanent_location in face of adversity! + #Don't let it fall to 'PROC' or 'CART'. Otherwise it will be forever lost! + my $locations = GetRealItemLocations( $item->{itemnumber} ); + $item->{'permanent_location'} = $locations->{'permanent_location'}; + } } if (exists $item->{'timestamp'}) { delete $item->{'timestamp'}; -- 2.1.0