X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_export%2Fphone_sqlopensips.pm;h=3d01c1624d0b41f7221cae031088201b349c2b9a;hb=395cc72629d31c8dcd138acf423e66d2d73d89d2;hp=8a3d3a17b1891883379121474cf5d0ba1e1395cd;hpb=8ae589024036a94bb71da0e05f645b00697e271f;p=freeside.git diff --git a/FS/FS/part_export/phone_sqlopensips.pm b/FS/FS/part_export/phone_sqlopensips.pm index 8a3d3a17b..3d01c1624 100644 --- a/FS/FS/part_export/phone_sqlopensips.pm +++ b/FS/FS/part_export/phone_sqlopensips.pm @@ -7,6 +7,7 @@ use FS::Record qw( dbh qsearch qsearchs ); use FS::part_export; use FS::svc_phone; use FS::export_svc; +use LWP::UserAgent; @ISA = qw(FS::part_export); @@ -14,6 +15,9 @@ tie %options, 'Tie::IxHash', 'datasrc' => { label=>'DBI data source ' }, 'username' => { label=>'Database username' }, 'password' => { label=>'Database password' }, + 'xmlrpc_url' => { label=>'XMLRPC URL' }, + # XXX: in future, add non-agent-virtualized config, i.e. per-export setting of gwlist, routeid, description, etc. + # and/or setting description from the phone_name column ; %info = ( @@ -27,14 +31,21 @@ sub rebless { shift; } sub _export_insert { my($self, $svc_x) = (shift, shift); + + my $conf = new FS::Conf; + my $agentnum = $svc_x->cust_svc->cust_pkg->cust_main->agentnum || 0; + my $gwlist = $conf->config('opensips_gwlist',$agentnum) || ''; + my $description = $conf->config('opensips_description',$agentnum) || ''; + my $route = $conf->config('opensips_route',$agentnum) || ''; + my $dbh = $self->opensips_connect; my $sth = $dbh->prepare("insert into dr_rules ". "( groupid, prefix, timerec, routeid, gwlist, description ) ". " values ( ?, ?, ?, ?, ?, ? )") or die $dbh->errstr; - $sth->execute('0',$svc_x->phonenum,'',$svc_x->route,'', - $svc_x->phone_name) or die $sth->errstr; + $sth->execute('0',$svc_x->phonenum,'',$route,$gwlist,$description) + or die $sth->errstr; $dbh->disconnect; - ''; + $self->dr_reload; # XXX: if this fails, do we delete what we just inserted? } sub opensips_connect { @@ -44,30 +55,7 @@ sub opensips_connect { } sub _export_replace { - my( $self, $new, $old ) = (shift, shift, shift); - my @update = (); - my @paramvalues = (); - - if($old->route ne $new->route){ - push @update, 'routeid = ?'; - push @paramvalues, $new->route; - } - - if($old->phone_name ne $new->phone_name) { - push @update, 'description = ?'; - push @paramvalues, $new->phone_name; - } - - if(scalar(@update)) { - my $update_str = join(' and ',@update); - my $dbh = $self->opensips_connect; - my $sth = $dbh->prepare("update dr_rules set $update_str " . - " where prefix = ? ") or die $dbh->errstr; - push @paramvalues, $old->phonenum; - $sth->execute(@paramvalues) or die $sth->errstr; - $dbh->disconnect; - } - ''; + ''; } sub _export_suspend { @@ -87,6 +75,21 @@ sub _export_delete { or die $dbh->errstr; $sth->execute($svc_x->phonenum) or die $sth->errstr; $dbh->disconnect; - ''; + $self->dr_reload; # XXX: if this fails, do we re-insert what we just deleted? +} + +sub dr_reload { + my $self = shift; + my $reqxml = " + + dr_reload +"; + my $ua = LWP::UserAgent->new; + my $resp = $ua->post( $self->option('xmlrpc_url'), + Content_Type => 'text/xml', + Content => $reqxml ); + return "invalid HTTP response from OpenSIPS: " . $resp->status_line + unless $resp->is_success; + ''; }