[freeside-commits] freeside/FS/FS cust_main_Mixin.pm, 1.11.2.1, 1.11.2.2

Mark Wells mark at wavetail.420.am
Thu Feb 2 17:09:23 PST 2012


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv17780/FS/FS

Modified Files:
      Tag: FREESIDE_2_3_BRANCH
	cust_main_Mixin.pm 
Log Message:
email to search results, #16246

Index: cust_main_Mixin.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main_Mixin.pm,v
retrieving revision 1.11.2.1
retrieving revision 1.11.2.2
diff -u -w -d -r1.11.2.1 -r1.11.2.2
--- cust_main_Mixin.pm	16 Sep 2011 00:15:47 -0000	1.11.2.1
+++ cust_main_Mixin.pm	3 Feb 2012 01:09:21 -0000	1.11.2.2
@@ -388,6 +388,7 @@
 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 @@
     }
 
     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 @@
       );
     } #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 @@
         'status'     => 'failed',
         'statustext' => $error,
       };
-      $queue->insert(@message);
+      $queue->insert(%message);
       push @retry_jobs, $queue;
     }
     else {



More information about the freeside-commits mailing list