Bug 25421: Remove use of Koha::Libraries->pickup_locations
authorTomas Cohen Arazi <tomascohen@theke.io>
Fri, 8 May 2020 13:04:30 +0000 (10:04 -0300)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 12 May 2020 10:00:14 +0000 (11:00 +0100)
The current implementation uses Koha::Libraries->pickup_locations which
is problematic and due to be removed by bug 24368. This patch makes the
trivial change of just searching for libraries that are marked with
pickup_location => 1.

Calls to Koha::Item->pickup_locations and Koha::Biblio->pickup_locations
are as well adapted to the new arrayref return value.

To test:
1. Pick a record with only one item
2. Place a biblio-level hold on it
3. Edit the items: remove the item
4. Go to the Holds tab
=> FAIL: It explodes
5. Apply this patch and restart:
   $ sudo koha-plack --restart kohadev
6. Go back and go to the holds tab again
=> SUCCESS: No failure!
7. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Didier Gautheron <didier.gautheron@biblibre.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Koha/Template/Plugin/Branches.pm

index 2d246c0..e5c8bdc 100644 (file)
@@ -113,17 +113,25 @@ sub pickup_locations {
             $patron = Koha::Patrons->find($patron);
         }
 
-        if($item) {
-            $item = Koha::Items->find($item) unless ref($item) eq 'Koha::Item';
-            @libraries = map { $_->unblessed } $item->pickup_locations( {patron => $patron} ) if defined $item;
-        } elsif($biblio) {
-            $biblio = Koha::Biblios->find($biblio) unless ref($biblio) eq 'Koha::Biblio';
-            @libraries = map { $_->unblessed } $biblio->pickup_locations( {patron => $patron} ) if defined $biblio;
+        if ($item) {
+            $item = Koha::Items->find($item)
+              unless ref($item) eq 'Koha::Item';
+            @libraries = @{ $item->pickup_locations( { patron => $patron } ) }
+              if defined $item;
+        }
+        elsif ($biblio) {
+            $biblio = Koha::Biblios->find($biblio)
+              unless ref($biblio) eq 'Koha::Biblio';
+            @libraries = @{ $biblio->pickup_locations( { patron => $patron } ) }
+              if defined $biblio;
         }
-
     }
 
-    @libraries = Koha::Libraries->pickup_locations() unless @libraries;
+    @libraries = Koha::Libraries->search( { pickup_location => 1 },
+        { order_by => ['branchname'] } )->as_list
+      unless @libraries;
+
+    @libraries = map { $_->unblessed } @libraries;
 
     for my $l (@libraries) {
         if ( defined $selected and $l->{branchcode} eq $selected