subject => $subject,
context_org => $holdings_context_org->shortname,
sort_by => $bib_sort,
- sort_dir => $sort_dir,
- preview => $preview
+ sort_dir => $sort_dir
};
if ($for_print) {
} elsif ($for_email) {
- return $U->fire_object_event(undef, 'biblio.format.record_entry.email', [ $bucket ], $event_context_org, undef, [ $usr_data ])
- if ($preview);
-
- $U->create_events_for_hook('biblio.format.record_entry.email', $bucket, $event_context_org, undef, $usr_data, 1);
+ my $preview_event = $U->fire_object_event(undef, 'biblio.format.record_entry.email.preview', [ $bucket ], $event_context_org, undef, [ $usr_data ]);
+ if ($preview) {
+ return $preview_event;
+ } else {
+ # this is for backward compatibility; the non-preview call isn't currently used...
+ $self->method_lookup('open-ils.search.biblio.record.email.send_output')->run($auth, $preview_event->id);
+ }
}
return undef;
--- /dev/null
+package OpenILS::Application::Trigger::Reactor::PreviewEmail;
+use strict; use warnings;
+use Data::Dumper;
+use OpenSRF::Utils::SettingsClient;
+use OpenSRF::Utils::Logger qw/:logger/;
+$Data::Dumper::Indent = 0;
+use base 'OpenILS::Application::Trigger::Reactor';
+
+sub ABOUT {
+ return <<ABOUT;
+
+The PreviewEmail reactor generates the contents of an email to view and
+potentially send later.
+
+The value at /opensrf/default/email_notify/sender_address is passed into
+the template as the 'default_sender' variable.
+
+No default template is assumed, and all information other than the
+default_sender that the system provides is expected to be gathered by the
+Event Definition through either Environment or Parameter definitions.
+
+ABOUT
+}
+
+sub handler {
+ my $self = shift;
+ my $env = shift;
+
+ my $conf = OpenSRF::Utils::SettingsClient->new;
+ $$env{default_sender} = $conf->config_value('email_notify', 'sender_address');
+
+ my $text = $self->run_TT($env);
+ if (!$text) {
+ return 0;
+ } else {
+ $logger->info("PreviewEmail Reactor: successfully generated email");
+ return 1;
+ }
+}
+
+1;
+
my $text = encode_utf8($self->run_TT($env));
return 0 if (!$text);
- if ($$env{user_data} && ref($$env{user_data}) =~ /HASH/ && $$env{user_data}{preview}) {
- $logger->info("SendEmail Reactor: success in preview mode, not sending email");
- return 1;
- }
my $sender = Email::Send->new({mailer => 'SMTP'});
$sender->mailer_args([Host => $smtp]);
'description'
)
);
+INSERT INTO action_trigger.reactor (module,description) VALUES
+( 'PreviewEmail',
+ oils_i18n_gettext(
+ 'PreviewEmail',
+ 'Preview an email based on a user-defined template',
+ 'atreact',
+ 'description'
+ )
+);
-- TODO: build a PDF generator
--INSERT INTO action_trigger.reactor (module,description) VALUES
);
INSERT INTO action_trigger.hook (key,core_type,description,passive) VALUES (
- 'biblio.format.record_entry.email',
+ 'biblio.format.record_entry.email.preview',
'cbreb',
oils_i18n_gettext(
- 'biblio.format.record_entry.email',
+ 'biblio.format.record_entry.email.preview',
'An email has been requested for one or more biblio record entries.',
'ath',
'description'
31,
TRUE,
1,
- 'biblio.record_entry.email',
- 'biblio.format.record_entry.email',
+ 'biblio.record_entry.email.preview',
+ 'biblio.format.record_entry.email.preview',
'NOOP_True',
- 'SendEmail',
+ 'PreviewEmail',
'DeleteTempBiblioBucket',
'DeleteTempBiblioBucket',
'owner',
SELECT 1, 'Full', TRUE, id FROM action_trigger.event_definition WHERE hook = 'biblio.format.record_entry.print';
INSERT INTO action_trigger.event_def_group (id, owner, hook, name)
- VALUES (2,1,'biblio.format.record_entry.email','Email Record(s)');
+ VALUES (2,1,'biblio.format.record_entry.email.preview','Email Record(s)');
INSERT INTO action_trigger.event_def_group_member (grp, name, event_def)
- SELECT 2, 'Brief', id FROM action_trigger.event_definition WHERE hook = 'biblio.format.record_entry.email';
+ SELECT 2, 'Brief', id FROM action_trigger.event_definition WHERE hook = 'biblio.format.record_entry.email.preview';
INSERT INTO action_trigger.event_def_group_member (grp, name, holdings, event_def)
- SELECT 2, 'Full', TRUE, id FROM action_trigger.event_definition WHERE hook = 'biblio.format.record_entry.email';
+ SELECT 2, 'Full', TRUE, id FROM action_trigger.event_definition WHERE hook = 'biblio.format.record_entry.email.preview';
INSERT into config.org_unit_setting_type (name, label, description, datatype)
VALUES (
SELECT 1, 'Full', TRUE, id FROM action_trigger.event_definition WHERE hook = 'biblio.format.record_entry.print';
INSERT INTO action_trigger.event_def_group (id, owner, hook, name)
- VALUES (2,1,'biblio.format.record_entry.email','Email Record(s)');
+ VALUES (2,1,'biblio.format.record_entry.email.preview','Email Record(s)');
INSERT INTO action_trigger.event_def_group_member (grp, name, event_def)
- SELECT 2, 'Brief', id FROM action_trigger.event_definition WHERE hook = 'biblio.format.record_entry.email';
+ SELECT 2, 'Brief', id FROM action_trigger.event_definition WHERE hook = 'biblio.format.record_entry.email.preview';
INSERT INTO action_trigger.event_def_group_member (grp, name, holdings, event_def)
- SELECT 2, 'Full', TRUE, id FROM action_trigger.event_definition WHERE hook = 'biblio.format.record_entry.email';
+ SELECT 2, 'Full', TRUE, id FROM action_trigger.event_definition WHERE hook = 'biblio.format.record_entry.email.preview';
+
+INSERT INTO action_trigger.reactor VALUES ('PreviewEmail', 'Preview an email based on a user-defined template');
+
+UPDATE action_trigger.hook SET key = 'biblio.format.record_entry.email.preview' where key = 'biblio.format.record_entry.email';
+
+-- Doing these next two separately, as the second might not apply
+UPDATE action_trigger.event_definition SET name = 'biblio.record_entry.email.preview', reactor = 'PreviewEmail', hook = 'biblio.format.record_entry.email.preview' WHERE hook = 'biblio.format.record_entry.email';
UPDATE action_trigger.event_definition SET template = $$
[%- USE date -%]
[% END %]
[% END %]
-$$ WHERE hook = 'biblio.format.record_entry.email';
+$$ WHERE hook = 'biblio.format.record_entry.email.preview';
+-- TODO: check for MD5 of old template before clobbering?
UPDATE action_trigger.event_definition SET template = $$
<div>
</ol>
</div>
$$ WHERE hook = 'biblio.format.record_entry.print';
+-- TODO: check for MD5 of old template before clobbering?
COMMIT;