diff options
author | Mark Wells <mark@freeside.biz> | 2015-08-27 19:18:42 -0700 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2015-08-30 17:48:49 -0700 |
commit | 5a2a2f8a6f95738758b43cdbbfa48dd7830de2d5 (patch) | |
tree | 98500c31f92e741212d0d7c3355e4f744e0102f1 /FS/FS/cust_main_Mixin.pm | |
parent | 11c81c66b62ac176c167583f7b68ed80bd4239c9 (diff) |
#21564, external message services: preview and send messages through the UI
Diffstat (limited to 'FS/FS/cust_main_Mixin.pm')
-rw-r--r-- | FS/FS/cust_main_Mixin.pm | 41 |
1 files changed, 15 insertions, 26 deletions
diff --git a/FS/FS/cust_main_Mixin.pm b/FS/FS/cust_main_Mixin.pm index bdad511..3d05f84 100644 --- a/FS/FS/cust_main_Mixin.pm +++ b/FS/FS/cust_main_Mixin.pm @@ -445,6 +445,10 @@ sub email_search_result { my $success = 0; my %sent_to = (); + if ( !$msg_template ) { + # XXX create on the fly + } + #eventually order+limit magic to reduce memory use? foreach my $obj ( qsearch($sql_query) ) { @@ -459,36 +463,19 @@ sub email_search_result { } my $cust_main = $obj->cust_main; - tie my %message, 'Tie::IxHash'; if ( !$cust_main ) { next; # unlinked object; nothing else we can do } - if ( $msg_template ) { - # Now supports other context objects. - %message = $msg_template->prepare( - 'cust_main' => $cust_main, - 'object' => $obj, - ); - } - else { - my @to = $cust_main->invoicing_list_emailonly; - next if !@to; - - %message = ( - 'from' => $from, - 'to' => \@to, - 'subject' => $subject, - 'html_body' => $html_body, - 'text_body' => $text_body, - 'custnum' => $cust_main->custnum, - ); - } #if $msg_template + my $cust_msg = $msg_template->prepare( + 'cust_main' => $cust_main, + 'object' => $obj, + ); # For non-cust_main searches, we avoid duplicates based on message - # body text. + # body text. my $unique = $cust_main->custnum; - $unique .= sha1($message{'text_body'}) if $class ne 'FS::cust_main'; + $unique .= sha1($cust_msg->text_body) if $class ne 'FS::cust_main'; if( $sent_to{$unique} ) { # avoid duplicates $dups++; @@ -497,18 +484,20 @@ sub email_search_result { $sent_to{$unique} = 1; - $error = send_email( generate_email( %message ) ); + $error = $cust_msg->send; if($error) { # queue the sending of this message so that the user can see what we # tried to do, and retry if desired + # (note the cust_msg itself also now has a status of 'failed'; that's + # fine, as it will get its status reset if we retry the job) my $queue = new FS::queue { - 'job' => 'FS::Misc::process_send_email', + 'job' => 'FS::cust_msg::process_send', 'custnum' => $cust_main->custnum, 'status' => 'failed', 'statustext' => $error, }; - $queue->insert(%message); + $queue->insert($cust_msg->custmsgnum); push @retry_jobs, $queue; } else { |