[freeside-commits] branch master updated. f2e15ed1a7e7b5938f32e1bd961082bed83de662

Ivan ivan at 420.am
Fri Mar 23 19:47:14 PDT 2012


The branch, master has been updated
       via  f2e15ed1a7e7b5938f32e1bd961082bed83de662 (commit)
      from  6e8d47545088670085190e5a3a923cff930174e4 (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 f2e15ed1a7e7b5938f32e1bd961082bed83de662
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Fri Mar 23 19:47:13 2012 -0700

    enhance contacts: multiple email addresses, RT#16819

diff --git a/FS/FS/contact.pm b/FS/FS/contact.pm
index 774aed0..0b50dcc 100644
--- a/FS/FS/contact.pm
+++ b/FS/FS/contact.pm
@@ -135,15 +135,21 @@ sub insert {
   }
 
   if ( $self->get('emailaddress') =~ /\S/ ) {
-    my $contact_email = new FS::contact_email {
-      'contactnum'   => $self->contactnum,
-      'emailaddress' => $self->get('emailaddress'),
-    };
-    $error = $contact_email->insert;
-    if ( $error ) {
-      $dbh->rollback if $oldAutoCommit;
-      return $error;
+
+    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;
+      }
+
     }
+
   }
 
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
@@ -160,7 +166,38 @@ Delete this record from the database.
 
 # the delete method can be inherited from FS::Record
 
-# XXX delete contact_phone, contact_email
+sub delete {
+  my $self = shift;
+
+  local $SIG{HUP} = 'IGNORE';
+  local $SIG{INT} = 'IGNORE';
+  local $SIG{QUIT} = 'IGNORE';
+  local $SIG{TERM} = 'IGNORE';
+  local $SIG{TSTP} = 'IGNORE';
+  local $SIG{PIPE} = 'IGNORE';
+
+  my $oldAutoCommit = $FS::UID::AutoCommit;
+  local $FS::UID::AutoCommit = 0;
+  my $dbh = dbh;
+
+  foreach my $object ( $self->contact_phone, $self->contact_email ) {
+    my $error = $object->delete;
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return $error;
+    }
+  }
+
+  my $error = $self->SUPER::delete;
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return $error;
+  }
+
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+  '';
+
+}
 
 =item replace OLD_RECORD
 
@@ -211,6 +248,34 @@ sub replace {
     }
   }
 
+  if ( defined($self->get('emailaddress')) ) {
+
+    #ineffecient but whatever, how many email addresses can there be?
+
+    foreach my $contact_email ( $self->contact_email ) {
+      my $error = $contact_email->delete;
+      if ( $error ) {
+        $dbh->rollback if $oldAutoCommit;
+        return $error;
+      }
+    }
+
+    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;
+      }
+
+    }
+
+  }
+
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
 
   '';
@@ -286,6 +351,22 @@ sub line {
   $data;
 }
 
+sub cust_location {
+  my $self = shift;
+  return '' unless $self->locationnum;
+  qsearchs('cust_location', { 'locationnum' => $self->locationnum } );
+}
+
+sub contact_phone {
+  my $self = shift;
+  qsearch('contact_phone', { 'contactnum' => $self->contactnum } );
+}
+
+sub contact_email {
+  my $self = shift;
+  qsearch('contact_email', { 'contactnum' => $self->contactnum } );
+}
+
 =back
 
 =head1 BUGS
diff --git a/httemplate/elements/contact.html b/httemplate/elements/contact.html
index eea3694..3efa232 100644
--- a/httemplate/elements/contact.html
+++ b/httemplate/elements/contact.html
@@ -21,11 +21,7 @@
 %             && $contact_phone->countrycode ne '1';
 %         }
 %       } elsif ( $field eq 'emailaddress' ) {
-%         #XXX multiple not yet supported
-%         my $contact_email = qsearchs('contact_email', {
-%           'contactnum' => $curr_value,
-%         });
-%         $value = $contact_email->emailaddress if $contact_email;
+%         $value = join(', ', map $_->emailaddress, $contact->contact_email);
 %       } else {
 %         $value = $contact->get($field);
 %       }

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

Summary of changes:
 FS/FS/contact.pm                 |   99 ++++++++++++++++++++++++++++++++++----
 httemplate/elements/contact.html |    6 +--
 2 files changed, 91 insertions(+), 14 deletions(-)




More information about the freeside-commits mailing list