X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcontact.pm;h=936d47cd0245951b72bfe70b53fbd61c5fdca00c;hb=61ad2af332888443d8dae59274693229d0258a97;hp=774aed08894fe5d5104560d8503636a7bf7fdfe6;hpb=0fb307c305e4bc2c9c27dc25a3308beae3a4d33c;p=freeside.git diff --git a/FS/FS/contact.pm b/FS/FS/contact.pm index 774aed088..936d47cd0 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; ''; @@ -259,8 +324,8 @@ sub check { || $self->ut_foreign_keyn('prospectnum', 'prospect_main', 'prospectnum') || $self->ut_foreign_keyn('custnum', 'cust_main', 'custnum') || $self->ut_foreign_keyn('locationnum', 'cust_location', 'locationnum') - || $self->ut_textn('last') - || $self->ut_textn('first') + || $self->ut_namen('last') + || $self->ut_namen('first') || $self->ut_textn('title') || $self->ut_textn('comment') || $self->ut_enum('disabled', [ '', 'Y' ]) @@ -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