From ff7ea322f7d9010643760f01f201a6329209763c Mon Sep 17 00:00:00 2001
From: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Date: Fri, 5 Aug 2011 16:01:09 -0400
Subject: [PATCH] Whoops. Do that availability test regard of whether
 hold_boundaries are used.

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
---
 .../lib/OpenILS/Application/Search/Biblio.pm       | 74 +++++++++++-----------
 1 file changed, 38 insertions(+), 36 deletions(-)

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm
index a8bcda24f1..79dec4d7a6 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm
@@ -2602,45 +2602,47 @@ sub rec_to_mr_rec_descriptors {
 
 	my $desc = $e->search_metabib_record_descriptor($search);
 
-    if ($hard_boundary) { # 0 (or "top") is the same as no setting
-        my $orgs = $e->json_query(
-            { from => [ 'actor.org_unit_descendants' => $pickup_lib, $hard_boundary ] }
-        );
+	my $query = {
+		distinct => 1,
+		select   => { 'bre' => ['id'] },
+		from	 => {
+			'bre' => {
+				'acn' => {
+					'join' => {
+						'acp' => {"join" => {"acpl" => {}, "ccs" => {}}}
+					  }
+				  }
+			 }
+		},
+		where => {
+			'+bre' => { id => \@recs },
+			'+acp' => {
+				holdable => 't',
+				deleted  => 'f'
+			},
+			"+ccs" => { holdable => 't' },
+			"+acpl" => { holdable => 't' }
+		}
+	};
 
-        my $good_records = $e->json_query(
-            { distinct => 1,
-              select   => { 'bre' => ['id'] },
-              from     => {
-                  'bre' => {
-                      'acn' => {
-                          'join' => {
-                              'acp' => {"join" => {"acpl" => {}, "ccs" => {}}}
-                            }
-                        }
-                   }
-              },
-              where    => {
-                '+bre' => { id => \@recs },
-                '+acp' => {
-                    holdable => 't',
-                    circ_lib => [ map { $_->{id} } @$orgs ],
-                    deleted  => 'f'
-                },
-                "+ccs" => { holdable => 't' },
-                "+acpl" => { holdable => 't' }
-              }
-            }
-        );
+	if ($hard_boundary) { # 0 (or "top") is the same as no setting
+		my $orgs = $e->json_query(
+			{ from => [ 'actor.org_unit_descendants' => $pickup_lib, $hard_boundary ] }
+		) or return $e->die_event;
 
-        my @keep;
-        for my $d (@$desc) {
-            if ( grep { $d->record == $_->{id} } @$good_records ) {
-                push @keep, $d;
-            }
-        }
+		$query->{where}->{"+acp"}->{circ_lib} = [ map { $_->{id} } @$orgs ];
+	}
 
-        $desc = \@keep;
-    }
+	my $good_records = $e->json_query($query) or return $e->die_event;
+
+	my @keep;
+	for my $d (@$desc) {
+		if ( grep { $d->record == $_->{id} } @$good_records ) {
+			push @keep, $d;
+		}
+	}
+
+	$desc = \@keep;
 
 	return { metarecord => $mrec, descriptors => $desc };
 }
-- 
2.11.0