[open-ils-commits] r15495 - trunk/Open-ILS/src/perlmods/OpenILS/Application (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Feb 10 13:15:05 EST 2010
Author: erickson
Date: 2010-02-10 13:15:01 -0500 (Wed, 10 Feb 2010)
New Revision: 15495
Modified:
trunk/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm
Log:
added sub to find the most relevant event def by hook for a given context org unit
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm 2010-02-10 17:49:46 UTC (rev 15494)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm 2010-02-10 18:15:01 UTC (rev 15495)
@@ -1573,6 +1573,27 @@
}
+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 @@
$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;
+ $def = $self->find_event_def_by_hook($hook, $context_org, $e)
+ or return $e->event;
}
if($def->group_field) {
More information about the open-ils-commits
mailing list