summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorChristopher Burger <burgerc@freeside.biz>2019-01-08 16:43:34 -0500
committerChristopher Burger <burgerc@freeside.biz>2019-01-08 16:43:34 -0500
commitda863bce6c626f566e5e33e5a8896f6ae4aba470 (patch)
tree99692dc5a38255d1f7a0aa9d82962f694fa22ca9 /FS
parent0e8e082b68d6210eb8749ac6211b969818928f3d (diff)
RT# 81853 - updated contact replace to only add or delete email if it is changed.
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/contact.pm38
1 files changed, 23 insertions, 15 deletions
diff --git a/FS/FS/contact.pm b/FS/FS/contact.pm
index d6869ab..a2fc99c 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 ) {