[freeside-commits] branch FREESIDE_4_BRANCH updated. fe557e7e0d3d8077b2a4a15278a6f2dee5c04e95

Christopher Burger burgerc at freeside.biz
Tue Jan 8 14:08:42 PST 2019


The branch, FREESIDE_4_BRANCH has been updated
       via  fe557e7e0d3d8077b2a4a15278a6f2dee5c04e95 (commit)
      from  8d92a5062e720da98dfe28cd0f0e10e308fc65dd (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 fe557e7e0d3d8077b2a4a15278a6f2dee5c04e95
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Tue Jan 8 16:43:34 2019 -0500

    RT# 81853 - updated contact replace to only add or delete email if it is changed.

diff --git a/FS/FS/contact.pm b/FS/FS/contact.pm
index 094feea74..1801545b1 100644
--- a/FS/FS/contact.pm
+++ b/FS/FS/contact.pm
@@ -534,30 +534,38 @@ sub replace {
 
   if ( defined($self->hashref->{'emailaddress'}) ) {
 
-    #ineffecient but whatever, how many email addresses can there be?
-
+    my %contact_emails = ();
     foreach my $contact_email ( $self->contact_email ) {
-      my $error = $contact_email->delete;
-      if ( $error ) {
-        $dbh->rollback if $oldAutoCommit;
-        return $error;
-      }
+      $contact_emails{$contact_email->emailaddress} = '1';
     }
 
     foreach my $email ( split(/\s*,\s*/, $self->get('emailaddress') ) ) {
  
-      my $contact_email = new FS::contact_email {
-        'contactnum'   => $self->contactnum,
-        'emailaddress' => $email,
-      };
-      $error = $contact_email->insert;
-      if ( $error ) {
-        $dbh->rollback if $oldAutoCommit;
-        return $error;
+      unless ($contact_emails{$email}) {
+        my $contact_email = new FS::contact_email {
+          'contactnum'   => $self->contactnum,
+          'emailaddress' => $email,
+        };
+        $error = $contact_email->insert;
+        if ( $error ) {
+          $dbh->rollback if $oldAutoCommit;
+          return $error;
+        }
       }
+      else { delete($contact_emails{$email}); }
 
     }
 
+    foreach my $contact_email ( $self->contact_email ) {
+      if ($contact_emails{$contact_email->emailaddress}) {
+        my $error = $contact_email->delete;
+        if ( $error ) {
+          $dbh->rollback if $oldAutoCommit;
+          return $error;
+        }
+      }
+    }
+
   }
 
   unless ( $skip_fuzzyfiles ) { #unless ( $import || $skip_fuzzyfiles ) {

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

Summary of changes:
 FS/FS/contact.pm | 38 +++++++++++++++++++++++---------------
 1 file changed, 23 insertions(+), 15 deletions(-)




More information about the freeside-commits mailing list