summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormark <mark>2012-02-03 01:08:11 +0000
committermark <mark>2012-02-03 01:08:11 +0000
commit2103a18a3be93d38f2c1e69bea14a2681e382007 (patch)
tree0f4dc137d560a16245e2290b8d70d5910fe6e87b
parent194a775de9252e26f9f7615969489723ffbe46cc (diff)
email to search results, #16246
-rw-r--r--FS/FS/cust_main_Mixin.pm40
-rw-r--r--httemplate/misc/email-customers.html5
-rwxr-xr-xhttemplate/search/svc_acct.cgi4
3 files changed, 30 insertions, 19 deletions
diff --git a/FS/FS/cust_main_Mixin.pm b/FS/FS/cust_main_Mixin.pm
index d493060..7fcb5b5 100644
--- a/FS/FS/cust_main_Mixin.pm
+++ b/FS/FS/cust_main_Mixin.pm
@@ -388,6 +388,7 @@ in the job fail, the entire job will abort and return an error.
use Storable qw(thaw);
use MIME::Base64;
use Data::Dumper qw(Dumper);
+use Digest::SHA qw(sha1); # for duplicate checking
sub email_search_result {
my($class, $param) = @_;
@@ -438,32 +439,23 @@ sub email_search_result {
}
my $cust_main = $obj->cust_main;
- my @message;
+ tie my %message, 'Tie::IxHash';
if ( !$cust_main ) {
next; # unlinked object; nothing else we can do
}
- if( $sent_to{$cust_main->custnum} ) {
- # avoid duplicates
- $dups++;
- next;
- }
-
- $sent_to{$cust_main->custnum} = 1;
-
if ( $msg_template ) {
- # XXX add support for other context objects?
- # If we do that, handling of "duplicates" will
- # have to be smarter. Currently we limit to
- # one message per custnum because they'd all
- # be identical.
- @message = $msg_template->prepare( 'cust_main' => $cust_main );
+ # 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 = (
+ %message = (
'from' => $from,
'to' => \@to,
'subject' => $subject,
@@ -473,7 +465,19 @@ sub email_search_result {
);
} #if $msg_template
- $error = send_email( generate_email( @message ) );
+ # For non-cust_main searches, we avoid duplicates based on message
+ # body text.
+ my $unique = $cust_main->custnum;
+ $unique .= sha1($message{'text_body'}) if $class ne 'FS::cust_main';
+ if( $sent_to{$unique} ) {
+ # avoid duplicates
+ $dups++;
+ next;
+ }
+
+ $sent_to{$unique} = 1;
+
+ $error = send_email( generate_email( %message ) );
if($error) {
# queue the sending of this message so that the user can see what we
@@ -484,7 +488,7 @@ sub email_search_result {
'status' => 'failed',
'statustext' => $error,
};
- $queue->insert(@message);
+ $queue->insert(%message);
push @retry_jobs, $queue;
}
else {
diff --git a/httemplate/misc/email-customers.html b/httemplate/misc/email-customers.html
index d981aea..b87a1bf 100644
--- a/httemplate/misc/email-customers.html
+++ b/httemplate/misc/email-customers.html
@@ -191,7 +191,10 @@ if ( $cgi->param('action') eq 'preview' ) {
$sql_query->{'order_by'} = '';
my $object = qsearchs($sql_query);
my $cust = $object->cust_main;
- my %message = $msg_template->prepare( 'cust_main' => $cust );
+ my %message = $msg_template->prepare(
+ 'cust_main' => $cust,
+ 'object' => $object
+ );
($from, $subject, $html_body) = @message{'from', 'subject', 'html_body'};
}
}
diff --git a/httemplate/search/svc_acct.cgi b/httemplate/search/svc_acct.cgi
index be649a5..92e1c50 100755
--- a/httemplate/search/svc_acct.cgi
+++ b/httemplate/search/svc_acct.cgi
@@ -11,6 +11,10 @@
'color' => \@color,
'style' => \@style,
'footer' => \@footer,
+ 'html_init' => include('/elements/email-link.html',
+ 'search_hash' => \%search_hash,
+ 'table' => 'svc_acct'
+ ),
&>
<%once>