[open-ils-commits] r12293 - in trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger: . Reactor (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue Feb 24 22:23:07 EST 2009
Author: miker
Date: 2009-02-24 22:23:05 -0500 (Tue, 24 Feb 2009)
New Revision: 12293
Added:
trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/
trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/StaticEmail.pm
Modified:
trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Event.pm
Log:
start of a generic static email test reactor
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Event.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Event.pm 2009-02-25 03:06:32 UTC (rev 12292)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Event.pm 2009-02-25 03:23:05 UTC (rev 12293)
@@ -293,6 +293,8 @@
my $state = shift;
return undef unless ($state);
+ my $fields = shift;
+
if ($self->standalone) {
$self->editor->xact_begin || return undef;
}
@@ -303,6 +305,10 @@
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' );
Added: trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/StaticEmail.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/StaticEmail.pm (rev 0)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/StaticEmail.pm 2009-02-25 03:23:05 UTC (rev 12293)
@@ -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 = <<TT;
+To: [%- env.params.recipient -%]
+From: [%- env.params.sender -%]
+Subject: [%- env.params.subject -%]
+
+[% env.params.body %]
+TT
+
+sub handler {
+ my $self = shift;
+ my $env = shift;
+
+ my $conf = OpenSRF::Utils::SettingsClient->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;
+
More information about the open-ils-commits
mailing list