X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_main_Mixin.pm;fp=FS%2FFS%2Fcust_main_Mixin.pm;h=867d43e60996d4b7e2091a8ec2d4881b1567c87f;hp=3d05f8473a49ac1cf2882b60f7d6cc3f019b7907;hb=fc672686f119da0b3b34fd3c73acc3fea81262e6;hpb=956df0bc6383ed0513d4dd00668f3b24c42ba1e4 diff --git a/FS/FS/cust_main_Mixin.pm b/FS/FS/cust_main_Mixin.pm index 3d05f8473..867d43e60 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.