From efb83e6c54b0cbd00415b23eab0376c130953247 Mon Sep 17 00:00:00 2001
From: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Date: Wed, 1 Feb 2012 16:58:45 -0500
Subject: [PATCH] =?utf8?q?TPAC:=20Avoid=20hold=20placement=20problems=20?=
 =?utf8?q?=C3=A0=20la=2080d5c4a4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

A commit written in October and merged quickly (80d5c4a4) was designed
to avoid problems with a middle layer method that sometimes returns hash
refs and sometimes returns array refs.

A commit written in September but not merged until January (a663dfed)
affected neighboring code, but was not aware of the other code to dance
around hash refs and array refs (just read the commit messages of each
to see what I mean, with attention to the changes in
WWW/EGCatLoader/Account.pm).

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
---
 .../perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm
index 7b0c1a18eb..489594ce2f 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm
@@ -893,15 +893,22 @@ sub attempt_hold_placement {
 
                     if (ref $result eq 'HASH') {
                         $hdata->{hold_failed_event} = $result->{last_event};
+
+                        if ($result->{age_protected_copy}) {
+                            $hdata->{could_override} = 1;
+                            $hdata->{age_protect} = 1;
+                        } else {
+                            $hdata->{could_override} = $self->test_could_override($hdata->{hold_failed_event});
+                        }
                     } elsif (ref $result eq 'ARRAY') {
-                        $hdata->{hold_failed_event} = pop @$result;
-                    }
+                        $hdata->{hold_failed_event} = $result->[0];
 
-                    if($result->{age_protected_copy}) {
-                        $hdata->{could_override} = 1;
-                        $hdata->{age_protect} = 1;
-                    } else {
-                        $hdata->{could_override} = $self->test_could_override($hdata->{hold_failed_event});
+                        if ($result->[3]) { # age_protect_only
+                            $hdata->{could_override} = 1;
+                            $hdata->{age_protect} = 1;
+                        } else {
+                            $hdata->{could_override} = $self->test_could_override($hdata->{hold_failed_event});
+                        }
                     }
                 }
             }
-- 
2.11.0