[freeside-commits] branch FREESIDE_2_3_BRANCH updated. 3e099fedc2952c9754c66d87f7a0ce9f1920f579
Ivan
ivan at 420.am
Fri Mar 23 19:47:15 PDT 2012
The branch, FREESIDE_2_3_BRANCH has been updated
via 3e099fedc2952c9754c66d87f7a0ce9f1920f579 (commit)
from 5719851af502c532bf6da05b46ca7210a7a3099d (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 3e099fedc2952c9754c66d87f7a0ce9f1920f579
Author: Ivan Kohler <ivan at freeside.biz>
Date: Fri Mar 23 19:47:14 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