}
}
- if ( $self->selfservice_access ) {
+ if ( $self->selfservice_access && ! length($self->_password) ) {
my $error = $self->send_reset_email( queue=>1 );
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
}
- foreach my $pf ( grep { /^phonetypenum(\d+)$/ && $self->get($_) }
+ foreach my $pf ( grep { /^phonetypenum(\d+)$/ }
keys %{ $self->hashref } ) {
$pf =~ /^phonetypenum(\d+)$/ or die "wtf (daily, the)";
my $phonetypenum = $1;
my %cp = ( 'contactnum' => $self->contactnum,
'phonetypenum' => $phonetypenum,
);
- my $contact_phone = qsearchs('contact_phone', \%cp)
- || new FS::contact_phone \%cp;
+ my $contact_phone = qsearchs('contact_phone', \%cp);
+
+ my $pv = $self->get($pf);
+ $pv =~ s/\s//g;
+
+ #if new value is empty, delete old entry
+ if (!$pv) {
+ if ($contact_phone) {
+ $error = $contact_phone->delete;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ }
+ next;
+ }
+
+ $contact_phone ||= new FS::contact_phone \%cp;
- my %cpd = _parse_phonestring( $self->get($pf) );
+ my %cpd = _parse_phonestring( $pv );
$contact_phone->set( $_ => $cpd{$_} ) foreach keys %cpd;
my $method = $contact_phone->contactphonenum ? 'replace' : 'insert';