[freeside-commits] branch FREESIDE_3_BRANCH updated. 7c22fd0aa3f0f251a16f5ad69cda8cf0d9256ba1

Mark Wells mark at 420.am
Fri Dec 9 14:11:25 PST 2016


The branch, FREESIDE_3_BRANCH has been updated
       via  7c22fd0aa3f0f251a16f5ad69cda8cf0d9256ba1 (commit)
      from  5dd8c04f5d4d760b1e186e67123c9b7d9c5d58c8 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 7c22fd0aa3f0f251a16f5ad69cda8cf0d9256ba1
Author: Mark Wells <mark at freeside.biz>
Date:   Fri Dec 9 14:11:13 2016 -0800

    avoid creating contacts that duplicate other contact emails, #73708

diff --git a/bin/create-billing-contacts-v3 b/bin/create-billing-contacts-v3
index 35b81f8..a4e7e12 100755
--- a/bin/create-billing-contacts-v3
+++ b/bin/create-billing-contacts-v3
@@ -25,19 +25,18 @@ if ( $opt{c} ) {
   $classnum = $class->classnum;
 }
 
-# Find all invoice destinations that are email addresses,
-# except those where the customer already has a contact with that
-# email address.
+# Find all invoice destinations that are email addresses, except those where
+# there is already a contact with that email address.
 my @invoice_dests = qsearch({
   select    => 'cust_main_invoice.*',
   table     => 'cust_main_invoice',
   hashref   => { 'dest' => { op=>'!=', value=>'POST' } },
-  addl_from => ' LEFT JOIN (contact JOIN contact_email USING (contactnum)) ON
-    (cust_main_invoice.custnum = contact.custnum AND
-     cust_main_invoice.dest    = contact_email.emailaddress)',
-  extra_sql => ' AND contact.contactnum IS NULL',
+  addl_from => ' LEFT JOIN contact_email ON
+     (cust_main_invoice.dest    = contact_email.emailaddress)',
+  extra_sql => ' AND contact_email.contactnum IS NULL',
 });
 print "Found email destinations: ".scalar(@invoice_dests)."\n";
+my %email_used;
   
 foreach my $invoice_dest (@invoice_dests) {
   my $cust_main = $invoice_dest->cust_main;
@@ -45,6 +44,11 @@ foreach my $invoice_dest (@invoice_dests) {
   my $first = $cust_main->get('first');
   my $email = $invoice_dest->dest;
   print "$first $last <$email>\n";
+  if (exists $email_used{$email}) {
+    print "-- in use by cust#$email_used{$email}\n";
+    next;
+  }
+  $email_used{$email} = $cust_main->custnum;
 
   my $contact = qsearchs('contact', {
     'custnum' => $invoice_dest->custnum,

-----------------------------------------------------------------------

Summary of changes:
 bin/create-billing-contacts-v3 |   18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)




More information about the freeside-commits mailing list