From: oajulianclementson <51331324+oajulianclementson@users.noreply.github.com> Date: Tue, 7 Jan 2020 17:14:17 +0000 (+0000) Subject: LP#1842297: Fix - finds org parent reliably X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=c4f60bd997a28b973fafbf97953d5da61350c37d;p=evergreen%2Fpines.git LP#1842297: Fix - finds org parent reliably --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm index f44e6ef049..4655f7f28d 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm @@ -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) = @_; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/OpenAthens.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/OpenAthens.pm index 8e338e7c8f..f5837400ed 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/OpenAthens.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/OpenAthens.pm @@ -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 => {