diff options
author | Mark Wells <mark@freeside.biz> | 2015-10-07 14:18:15 -0700 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2015-10-07 14:18:45 -0700 |
commit | 6b8c46fa00f08da19bf0c4899776d3f82ef524c6 (patch) | |
tree | 5aadbdf2744278de8c87a8f97583e8c9c822d108 /FS/FS | |
parent | 8b80447169366e4d586955abd8e72a7bcbad122d (diff) |
#37098: convert one-shot email notices to use message templates
Diffstat (limited to 'FS/FS')
-rw-r--r-- | FS/FS/cust_main_Mixin.pm | 22 | ||||
-rw-r--r-- | FS/FS/msg_template.pm | 6 |
2 files changed, 25 insertions, 3 deletions
diff --git a/FS/FS/cust_main_Mixin.pm b/FS/FS/cust_main_Mixin.pm index 3d05f84..867d43e 100644 --- a/FS/FS/cust_main_Mixin.pm +++ b/FS/FS/cust_main_Mixin.pm @@ -426,6 +426,18 @@ sub email_search_result { if ( $msgnum ) { $msg_template = qsearchs('msg_template', { msgnum => $msgnum } ) or die "msgnum $msgnum not found\n"; + } else { + $msg_template = FS::msg_template->new({ + from_addr => $from, + msgname => $subject, # maybe a timestamp also? + disabled => 'D', # 'D'raft + # msgclass, maybe + }); + $error = $msg_template->insert( + subject => $subject, + body => $html_body, + ); + return "$error (when creating draft template)" if $error; } my $sql_query = $class->search($param->{'search'}); @@ -446,7 +458,7 @@ sub email_search_result { my %sent_to = (); if ( !$msg_template ) { - # XXX create on the fly + die "email_search_result now requires a msg_template"; } #eventually order+limit magic to reduce memory use? @@ -516,6 +528,14 @@ sub email_search_result { } } # foreach $obj + # if the message template was created as "draft", change its status to + # "completed" + if ($msg_template->disabled eq 'D') { + $msg_template->set('disabled' => 'C'); + my $error = $msg_template->replace; + warn "$error (setting draft message template status)" if $error; + } + if(@retry_jobs) { # fail the job, but with a status message that makes it clear # something was sent. diff --git a/FS/FS/msg_template.pm b/FS/FS/msg_template.pm index 4c2ac4b..cf81f7e 100644 --- a/FS/FS/msg_template.pm +++ b/FS/FS/msg_template.pm @@ -66,7 +66,9 @@ global template. =item bcc_addr - Bcc all mail to this address. -=item disabled - disabled ('Y' or NULL). +=item disabled - disabled (NULL for not-disabled and selectable, 'D' for a +draft of a one-time message, 'C' for a completed one-time message, 'Y' for a +normal template disabled by user action). =back @@ -246,7 +248,7 @@ sub check { || $self->ut_text('msgname') || $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum') || $self->ut_textn('mime_type') - || $self->ut_enum('disabled', [ '', 'Y' ] ) + || $self->ut_enum('disabled', [ '', 'Y', 'D', 'S' ] ) || $self->ut_textn('from_addr') || $self->ut_textn('bcc_addr') # fine for now, but change this to some kind of dynamic check if we |