summaryrefslogtreecommitdiff
path: root/FS/FS/cust_main_Mixin.pm
diff options
context:
space:
mode:
authormark <mark>2010-10-02 00:32:21 +0000
committermark <mark>2010-10-02 00:32:21 +0000
commiteb02bd7d44776cadc4c17f72df508afd223b142f (patch)
tree27def60834d0a8f249167cbb3b92ca6f668f3338 /FS/FS/cust_main_Mixin.pm
parentd6c837efb2bf63450de150b29f2ef7514cd249b6 (diff)
avoid sending duplicate notices from package search, RT#10103
Diffstat (limited to 'FS/FS/cust_main_Mixin.pm')
-rw-r--r--FS/FS/cust_main_Mixin.pm16
1 files changed, 15 insertions, 1 deletions
diff --git a/FS/FS/cust_main_Mixin.pm b/FS/FS/cust_main_Mixin.pm
index b446d69..8c8553c 100644
--- a/FS/FS/cust_main_Mixin.pm
+++ b/FS/FS/cust_main_Mixin.pm
@@ -423,7 +423,9 @@ sub email_search_result {
my( $num, $last, $min_sec ) = (0, time, 5); #progresbar foo
my @retry_jobs = ();
+ my $dups = 0;
my $success = 0;
+ my %sent_to = ();
#eventually order+limit magic to reduce memory use?
foreach my $obj ( qsearch($sql_query) ) {
@@ -443,9 +445,21 @@ sub email_search_result {
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 );
}
else {
@@ -494,7 +508,7 @@ sub email_search_result {
if(@retry_jobs) {
# fail the job, but with a status message that makes it clear
# something was sent.
- return "Sent $success, failed ".scalar(@retry_jobs).". Failed attempts placed in job queue.\n";
+ return "Sent $success, skipped $dups duplicate(s), failed ".scalar(@retry_jobs).". Failed attempts placed in job queue.\n";
}
return '';