From 41fa24d09c904ca200e70d44d6c6364d5d202a05 Mon Sep 17 00:00:00 2001 From: miker Date: Wed, 25 Feb 2009 03:23:05 +0000 Subject: [PATCH] start of a generic static email test reactor git-svn-id: svn://svn.open-ils.org/ILS/trunk@12293 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../OpenILS/Application/Trigger/Event.pm | 6 ++ .../Trigger/Reactor/StaticEmail.pm | 61 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/StaticEmail.pm diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Event.pm b/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Event.pm index aee5cb3cd7..580bff4708 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Event.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Event.pm @@ -293,6 +293,8 @@ sub update_state { my $state = shift; return undef unless ($state); + my $fields = shift; + if ($self->standalone) { $self->editor->xact_begin || return undef; } @@ -303,6 +305,10 @@ sub update_state { return undef; } + if ($fields && ref($fields)) { + $e->$_($$fields{$_}) for (keys %$fields); + } + $log->info( "Retrieved object ".$self->id." for update" ); $e->start_time( 'now' ) unless $e->start_time; $e->update_time( 'now' ); diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/StaticEmail.pm b/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/StaticEmail.pm new file mode 100644 index 0000000000..634dc709ba --- /dev/null +++ b/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/StaticEmail.pm @@ -0,0 +1,61 @@ +package OpenILS::Application::Trigger::Reactor::StaticEmail; +use Email::Send; +use OpenSRF::Utils::SettingsClient; +use OpenILS::Application::Trigger::Reactor; +use OpenSRF::Utils::Logger qw/:level/; + +use base 'OpenILS::Application::Trigger::Reactor'; + +my $log = 'OpenSRF::Utils::Logger'; + +my $default_template = <new; + my $smtp = $conf->config_value('email_notify', 'smtp_server'); + $$env{params}{sender} ||= $conf->config_value('email_notify', 'sender_address'); + $$env{params}{subject} ||= 'Test subject -- StaticEmail Reactor'; + $$env{params}{body} ||= 'Test body -- StaticEmail Reactor'; + + $$env{params}{recipient} or return 0; + + $logger->info("StaticEmail Reactor: sending email to ". + $$env{params}{recipient}." via SMTP server $smtp"); + + my $sender = Email::Send->new({mailer => 'SMTP'}); + $sender->mailer_args([Host => $smtp]); + + my $TT = $$env{template} || $default_template; + my $text = ''; # XXX TemplateToolkit stuff goes here... + + my $stat; + my $err; + + try { + $stat = $sender->send($text); + } catch Error with { + $err = $stat = shift; + $logger->error("StaticEmail Reactor: Email failed with error: $err"); + }; + + if( !$err and $stat and $stat->type eq 'success' ) { + $logger->info("StaticEmail Reactor: successfully sent email"); + return 1; + } else { + $logger->warn("StaticEmail Reactor: unable to send email: ".Dumper($stat)); + return 0; + } + +} + +1; + -- 2.43.2