Bug 17202: Don't report an item in a collection if the collection doesn't exist
authorNick Clemens <nick@bywatersolutions.com>
Wed, 7 Apr 2021 13:56:56 +0000 (13:56 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 28 Apr 2021 09:07:06 +0000 (11:07 +0200)
This simply adds a JOIN to the collections table - if the collection is gone
then the item is not considered to be in a rotating collection

Also remove variable to store the return that is not used later

To test:
Create a rotating collection
Add an item
Delete the rotating collection
View the db (SELECT * FROM collections_tracking;)
The item is still in the collection
Enable AutomaticItemReturn
Checkin the item at a branch not its home
The item does not get transferred home
Apply patch
Restart all the things
Check in the item, it is transferred home

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
C4/Circulation.pm
C4/RotatingCollections.pm

index 26aa616..10db0d2 100644 (file)
@@ -2165,7 +2165,6 @@ sub AddReturn {
     my $transfer = $item->get_transfer;
 
     # if we have a transfer to complete, we update the line of transfers with the datearrived
-    my $is_in_rotating_collection = C4::RotatingCollections::isItemInAnyCollection( $item->itemnumber );
     if ($transfer) {
         $validTransfer = 0;
         if ( $transfer->in_transit ) {
@@ -2277,7 +2276,7 @@ sub AddReturn {
     }
 
     # Transfer to returnbranch if Automatic transfer set or append message NeedsTransfer
-    if ( $validTransfer && !$is_in_rotating_collection
+    if ( $validTransfer && !C4::RotatingCollections::isItemInAnyCollection( $item->itemnumber )
         && ( $doreturn or $messages->{'NotIssued'} )
         and !$resfound
         and ( $branch ne $returnbranch )
index 5ee1982..2732a69 100644 (file)
@@ -571,7 +571,7 @@ sub isItemInAnyCollection {
     my $dbh = C4::Context->dbh;
 
     my $sth = $dbh->prepare(
-        "SELECT itemnumber FROM collections_tracking WHERE itemnumber = ?");
+        "SELECT itemnumber FROM collections_tracking JOIN collections USING (colId) WHERE itemnumber = ?");
     $sth->execute($itemnumber) or return (0);
 
     my $row = $sth->fetchrow_hashref;