LP#1842297: Fix - finds org parent reliably
authoroajulianclementson <51331324+oajulianclementson@users.noreply.github.com>
Tue, 7 Jan 2020 17:14:17 +0000 (17:14 +0000)
committerChris Sharp <csharp@georgialibraries.org>
Thu, 9 Jan 2020 15:41:52 +0000 (10:41 -0500)
Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/OpenAthens.pm

index f44e6ef..4655f7f 100644 (file)
@@ -1559,6 +1559,21 @@ sub org_unit_ancestor_at_depth {
     return ($resp) ? $resp->{id} : undef;
 }
 
+# returns the ID of the org unit ancestor at the specified distance
+sub get_org_unit_ancestor_at_distance {
+    my ($class, $org_id, $distance) = @_;
+    my $ancestors = OpenILS::Utils::CStoreEditor->new->json_query(
+        { from => ['actor.org_unit_ancestors_distance', $org_id] });
+    my @match = grep { $_->{distance} == $distance } @{$ancestors};
+    return (@match) ? $match[0]->{id} : undef;
+}
+
+# returns the ID of the org unit parent
+sub get_org_unit_parent {
+    my ($class, $org_id) = @_;
+    return $class->get_org_unit_ancestor_at_distance($org_id, 1);
+}
+
 # Returns the proximity value between two org units.
 sub get_org_unit_proximity {
     my ($class, $e, $from_org, $to_org) = @_;
index 8e338e7..f583740 100644 (file)
@@ -206,8 +206,7 @@ sub _get_openathens_config_for_org {
     my ($self, $org_id) = @_;
     my $e = new_editor();
 
-    my @org_ancestors = reverse @{$U->get_org_ancestors($org_id, 1)};
-    my $parent_org = $org_ancestors[1];
+    my $parent_org = $U->get_org_unit_parent($org_id);
 
     my $configs = $e->json_query({
         select => {