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:46:48 -0500
commitfe557e7e0d3d8077b2a4a15278a6f2dee5c04e95 (patch)
treedf74c92fb721eb14fe3d0d85edaf99250ead026b /FS
parent8d92a5062e720da98dfe28cd0f0e10e308fc65dd (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 094feea..1801545 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 ) {