[freeside-commits] branch master updated. da863bce6c626f566e5e33e5a8896f6ae4aba470

Christopher Burger burgerc at freeside.biz
Tue Jan 8 13:44:05 PST 2019


The branch, master has been updated
       via  da863bce6c626f566e5e33e5a8896f6ae4aba470 (commit)
      from  0e8e082b68d6210eb8749ac6211b969818928f3d (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 da863bce6c626f566e5e33e5a8896f6ae4aba470
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 d6869abc8..a2fc99c34 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