From: erickson Date: Wed, 10 Feb 2010 18:15:01 +0000 (+0000) Subject: added sub to find the most relevant event def by hook for a given context org unit X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=80ca117aa037d2ab6738a736d9af885b99b09630;p=evergreen%2Fpines.git added sub to find the most relevant event def by hook for a given context org unit git-svn-id: svn://svn.open-ils.org/ILS/trunk@15495 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm index b96521c96e..2a237576b1 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm @@ -1573,6 +1573,27 @@ sub xact_org { } +sub find_event_def_by_hook { + my($self, $hook, $context_org, $e) = @_; + + $e ||= OpenILS::Utils::CStoreEditor->new; + + my $orgs = $self->get_org_ancestors($context_org); + + # search from the context org up + for my $org_id (reverse @$orgs) { + + my $def = $e->search_action_trigger_event_definition( + {hook => $hook, owner => $org_id})->[0]; + + return $def if $def; + } + + return undef; +} + + + # If an event_def ID is not provided, use the hook and context org to find the # most appropriate event. create the event, fire it, then return the resulting # event with fleshed template_output and error_output @@ -1591,21 +1612,10 @@ sub fire_object_event { $auto_method .= '.include_inactive'; } else { - # find the most appropriate event def depending on context org - - my $orgs = $self->get_org_ancestors($context_org); - $orgs = $e->search_actor_org_unit( - [{id => $orgs}, {flesh => 1, flesh_fields => {aou => ['ou_type']}}]); - $orgs = [ sort { $a->ou_type->depth cmp $b->ou_type->depth } @$orgs ]; - for my $org (reverse @$orgs) { - $def = $e->search_action_trigger_event_definition( - {hook => $hook, owner => $org->id} - )->[0]; - last if $def; - } - - return $e->event unless $def; + # find the most appropriate event def depending on context org + $def = $self->find_event_def_by_hook($hook, $context_org, $e) + or return $e->event; } if($def->group_field) {