From 5ed6ccd7845d5985f7eac56c5e3b1b6b3e259300 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Fri, 9 Sep 2022 16:42:05 -0400 Subject: [PATCH] LP#1986479: fix lookup of user locale during A/T event processing This patch fixes an issue with the new user-locale-sensitive alternate Action Trigger template selection that supports letting patrons receive notifications in their preferred language. In particular, it corrects an assumption that the event target is the user itself. With the patch, the the event definition's context user path is consulted to identify the relevant user. To test ------- [1] Set up a patron with an email address and check out an item. [2] Use the Quick Receipt drop-down to attempt an email checkout receipt. [3] No email will be generated an the event will fail. The logs should contain something like Can't use an undefined value as a HASH reference at /usr/local/share/perl/5.28.1/OpenILS/Application/Trigger/Event.pm line 518. [4] Apply the patch and repeat steps 1 and 2. This time, the email should be sent (or, at least, the A/T event will be successfully processed). Signed-off-by: Galen Charlton Signed-off-by: Mike Rylander Signed-off-by: Galen Charlton --- .../perlmods/lib/OpenILS/Application/Trigger/Event.pm | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Event.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Event.pm index bd068e56c5..9c6c490760 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Event.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Event.pm @@ -492,6 +492,14 @@ sub build_environment { $self->environment->{usr_message}{title} = $self->event->event_def->message_title; $self->environment->{user_data} = $self->user_data; + # need to get the context user now... + if ($self->event->event_def->context_usr_path) { + my @usr_path = split(/\./, $self->event->event_def->context_usr_path); + $self->_object_by_path( $self->target, undef, [qw/context usr/], \@usr_path ); + } + + # ... so that we can see if the event output should use + # an alternative template in the patron's preferred locale my ($usr_locale, $alt_templates, $query, $query_result, $new_template_id); my $reactor = $self->environment->{event}->event_def->reactor; $query = { @@ -503,7 +511,7 @@ sub build_environment { } }; my $e = new_editor(xact=>1); - if ($reactor) { + if ($reactor && $self->environment->{context}->{usr}) { if ( $reactor eq 'SendEmail' or $reactor eq 'ProcessTemplate' or $reactor eq 'SendSMS') { @@ -512,7 +520,7 @@ sub build_environment { $query = { select => { au => ['locale'] }, from => 'au', - where => { id => $self->environment->{event}->target } + where => { id => $self->environment->{context}->{usr}->id } }; $query_result = $e->json_query($query); $usr_locale = @$query_result[0]->{locale}; @@ -573,11 +581,6 @@ sub build_environment { } } - if ($self->event->event_def->context_usr_path) { - my @usr_path = split(/\./, $self->event->event_def->context_usr_path); - $self->_object_by_path( $self->target, undef, [qw/context usr/], \@usr_path ); - } - if ($self->event->event_def->context_bib_path) { my @bib_path = split(/\./, $self->event->event_def->context_bib_path); $self->_object_by_path( $self->target, undef, [qw/context bib/], \@bib_path ); -- 2.11.0