X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fsvc_phone.pm;h=071b8073cddda48854a6b3d8cc93c1e5b3bfc76d;hb=0c09532569e55bbe54f4552b1f73e06f8b8ba8d4;hp=5cf3985c0afea2c67219ee844c55cff1100e0081;hpb=48bade3f01a672f235d61a29ad0d0b792fc80eab;p=freeside.git diff --git a/FS/FS/svc_phone.pm b/FS/FS/svc_phone.pm index 5cf3985c0..071b8073c 100644 --- a/FS/FS/svc_phone.pm +++ b/FS/FS/svc_phone.pm @@ -3,9 +3,12 @@ package FS::svc_phone; use strict; use vars qw( @ISA @pw_set $conf ); use FS::Conf; -use FS::Record qw( qsearch qsearchs ); +use FS::Record qw( qsearch qsearchs dbh ); +use FS::Msgcat qw(gettext); use FS::svc_Common; use FS::part_svc; +use FS::phone_device; +use FS::svc_pbx; @ISA = qw( FS::svc_Common ); @@ -65,6 +68,10 @@ Voicemail PIN =item phone_name +=item pbxsvc + +Optional svcnum from svc_pbx + =back =head1 METHODS @@ -101,7 +108,12 @@ sub table_info { disable_select => 1, }, 'sip_password' => 'SIP password', - 'name' => 'Name', + 'phone_name' => 'Name', + 'pbxsvc' => { label => 'PBX', + type => 'select-svc_pbx.html', + disable_inventory => 1, + disable_select => 1, #UI wonky, pry works otherwise + }, }, }; } @@ -118,6 +130,22 @@ Class method which returns an SQL fragment to search for the given string. sub search_sql { my( $class, $string ) = @_; + + if ( $conf->exists('svc_phone-allow_alpha_phonenum') ) { + $string =~ s/\W//g; + } else { + $string =~ s/\D//g; + } + + my $conf = new FS::Conf; + my $ccode = ( $conf->exists('default_phone_countrycode') + && $conf->config('default_phone_countrycode') + ) + ? $conf->config('default_phone_countrycode') + : '1'; + + $string =~ s/^$ccode//; + $class->search_sql_field('phonenum', $string ); } @@ -150,6 +178,39 @@ Delete this record from the database. =cut +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 $phone_device ( $self->phone_device ) { + my $error = $phone_device->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; + ''; + +} + # the delete method can be inherited from FS::Record =item replace OLD_RECORD @@ -207,6 +268,7 @@ sub check { || $self->ut_anything('sip_password') || $self->ut_numbern('pin') || $self->ut_textn('phone_name') + || $self->ut_foreign_keyn('pbxsvc', 'svc_pbx', 'svcnum' ) ; return $error if $error; @@ -325,6 +387,17 @@ sub radius_groups { (); } +=item phone_device + +Returns any FS::phone_device records associated with this service. + +=cut + +sub phone_device { + my $self = shift; + qsearch('phone_device', { 'svcnum' => $self->svcnum } ); +} + =back =head1 BUGS