From fd93bd0bf90836be82c5271bb36e46cca83735f4 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 30 Jun 2010 20:42:54 +0000 Subject: [PATCH] cust_main exports! cust_main-exports config option and part_export/cust_http.pm export, RT#8952 --- FS/FS/Conf.pm | 26 +++++++++++++ FS/FS/cust_main.pm | 74 ++++++++++++++++++++++++++++++++++++ FS/FS/part_export/cust_http.pm | 43 +++++++++++++++++++++ FS/FS/part_export/http.pm | 22 ++++++----- httemplate/config/config-process.cgi | 2 +- httemplate/config/config.cgi | 18 ++++++++- 6 files changed, 173 insertions(+), 12 deletions(-) create mode 100644 FS/FS/part_export/cust_http.pm diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 853a951ef..43d604c59 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -3782,6 +3782,32 @@ and customer address. Include units.', 'type' => 'checkbox', }, + { + 'key' => 'cust_main-exports', + 'section' => '', + 'description' => 'Export(s) to call on cust_main insert, modification and deletion.', + 'type' => 'select-sub', + 'multiple' => 1, + 'options_sub' => sub { + require FS::Record; + require FS::part_export; + my @part_export = + map { qsearch( 'part_export', {exporttype => $_ } ) } + keys %{FS::part_export::export_info('cust_main')}; + map { $_->exportnum => $_->exporttype.' to '.$_->machine } @part_export; + }, + 'option_sub' => sub { + require FS::Record; + require FS::part_export; + my $part_export = FS::Record::qsearchs( + 'part_export', { 'exportnum' => shift } + ); + $part_export + ? $part_export->exporttype.' to '.$part_export->machine + : ''; + }, + }, + { key => "apacheroot", section => "deprecated", description => "DEPRECATED", type => "text" }, { key => "apachemachine", section => "deprecated", description => "DEPRECATED", type => "text" }, { key => "apachemachines", section => "deprecated", description => "DEPRECATED", type => "text" }, diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 6d879bcd4..9c1629490 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -62,6 +62,7 @@ use FS::queue; use FS::part_pkg; use FS::part_event; use FS::part_event_condition; +use FS::part_export; #use FS::cust_event; use FS::type_pkgs; use FS::payment_gateway; @@ -546,6 +547,45 @@ sub insert { } } + # cust_main exports! + warn " exporting\n" if $DEBUG > 1; + + my $export_args = $options{'export_args'} || []; + + my @part_export = + map qsearch( 'part_export', {exportnum=>$_} ), + $conf->config('cust_main-exports'); #, $agentnum + + foreach my $part_export ( @part_export ) { + my $error = $part_export->export_insert($self, @$export_args); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "exporting to ". $part_export->exporttype. + " (transaction rolled back): $error"; + } + } + + #foreach my $depend_jobnum ( @$depend_jobnums ) { + # warn "[$me] inserting dependancies on supplied job $depend_jobnum\n" + # if $DEBUG; + # foreach my $jobnum ( @jobnums ) { + # my $queue = qsearchs('queue', { 'jobnum' => $jobnum } ); + # warn "[$me] inserting dependancy for job $jobnum on $depend_jobnum\n" + # if $DEBUG; + # my $error = $queue->depend_insert($depend_jobnum); + # if ( $error ) { + # $dbh->rollback if $oldAutoCommit; + # return "error queuing job dependancy: $error"; + # } + # } + # } + # + #} + # + #if ( exists $options{'jobnums'} ) { + # push @{ $options{'jobnums'} }, @jobnums; + #} + warn " insert complete; committing transaction\n" if $DEBUG > 1; @@ -1340,6 +1380,23 @@ sub delete { return $error; } + # cust_main exports! + + #my $export_args = $options{'export_args'} || []; + + my @part_export = + map qsearch( 'part_export', {exportnum=>$_} ), + $conf->config('cust_main-exports'); #, $agentnum + + foreach my $part_export ( @part_export ) { + my $error = $part_export->export_delete( $self ); #, @$export_args); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "exporting to ". $part_export->exporttype. + " (transaction rolled back): $error"; + } + } + $dbh->commit or die $dbh->errstr if $oldAutoCommit; ''; @@ -1478,6 +1535,23 @@ sub replace { } } + # cust_main exports! + + my $export_args = $options{'export_args'} || []; + + my @part_export = + map qsearch( 'part_export', {exportnum=>$_} ), + $conf->config('cust_main-exports'); #, $agentnum + + foreach my $part_export ( @part_export ) { + my $error = $part_export->export_replace( $self, $old, @$export_args); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "exporting to ". $part_export->exporttype. + " (transaction rolled back): $error"; + } + } + $dbh->commit or die $dbh->errstr if $oldAutoCommit; ''; diff --git a/FS/FS/part_export/cust_http.pm b/FS/FS/part_export/cust_http.pm new file mode 100644 index 000000000..d2781f64b --- /dev/null +++ b/FS/FS/part_export/cust_http.pm @@ -0,0 +1,43 @@ +package FS::part_export::cust_http; + +use vars qw( @ISA %info ); +use FS::part_export::http; +use Tie::IxHash; + +@ISA = qw( FS::part_export::http ); + +$options{'insert_data'}->{'default'} = join("\n", + "action 'insert'", + "custnum \$cust_main->custnum", + "first \$cust_main->first", + "last \$cust_main->get('last')", + ( map "$_ \$cust_main->$_", qw( company address1 address2 city county state zip country daytime night fax last ) ), + "email \$cust_main->invoicing_list_emailonly_scalar", +); +$options{'delete_data'}->{'default'} = join("\n", + "action 'delete'", + "custnum \$cust_main->custnum", +); +$options{'replace_data'}->{'default'} = join("\n", + "action 'replace'", + "custnum \$new_cust_main->custnum", + "first \$new_cust_main->first", + "last \$new_cust_main->get('last')", + ( map "$_ \$cust_main->$_", qw( company address1 address2 city county state zip country daytime night fax last ) ), + "email \$new_cust_main->invoicing_list_emailonly_scalar", +); + +%info = ( + 'svc' => 'cust_main', + 'desc' => 'Send an HTTP or HTTPS GET or POST request, for customers.', + 'options' => \%options, + 'notes' => <<'END' +Send an HTTP or HTTPS GET or POST to the specified URL on customer addition, +modification and deletion. For HTTPS support, +Crypt::SSLeay +or IO::Socket::SSL +is required. +END +); + +1; diff --git a/FS/FS/part_export/http.pm b/FS/FS/part_export/http.pm index 55d832966..9a216c148 100644 --- a/FS/FS/part_export/http.pm +++ b/FS/FS/part_export/http.pm @@ -1,12 +1,10 @@ package FS::part_export::http; -use vars qw(@ISA %info); +use base qw( FS::part_export ); +use vars qw( %options %info ); use Tie::IxHash; -use FS::part_export; -@ISA = qw(FS::part_export); - -tie my %options, 'Tie::IxHash', +tie %options, 'Tie::IxHash', 'method' => { label =>'Method', type =>'select', #options =>[qw(POST GET)], @@ -66,6 +64,10 @@ sub _export_command { return unless $self->option("${action}_data"); + my $cust_main = $svc_x->table eq 'cust_main' + ? $svc_x + : $svc_x->cust_svc->cust_pkg->cust_main; + $self->http_queue( $svc_x->svcnum, $self->option('method'), $self->option('url'), @@ -85,6 +87,10 @@ sub _export_replace { return unless $self->option('replace_data'); + my $new_cust_main = $new->table eq 'cust_main' + ? $new + : $new->cust_svc->cust_pkg->cust_main; + $self->http_queue( $svc_x->svcnum, $self->option('method'), $self->option('url'), @@ -100,10 +106,8 @@ sub _export_replace { sub http_queue { my($self, $svcnum) = (shift, shift); - my $queue = new FS::queue { - 'svcnum' => $svcnum, - 'job' => "FS::part_export::http::http", - }; + my $queue = new FS::queue { 'job' => "FS::part_export::http::http" }; + $queue->svcnum($svcnum) if $svcnum; $queue->insert( @_ ); } diff --git a/httemplate/config/config-process.cgi b/httemplate/config/config-process.cgi index c2b11b8fc..4e1c85a03 100644 --- a/httemplate/config/config-process.cgi +++ b/httemplate/config/config-process.cgi @@ -73,7 +73,7 @@ % my $record = qsearchs($table, { $pkey => $key }); % my $value = $record ? "$key: ".$record->$namecol() : $key; configCell.innerHTML = <% $value |js_string %>; -% } elsif ( $type eq 'select-sub' ) { +% } elsif ( $type eq 'select-sub' && ! $i->multiple ) { configCell.innerHTML = <% $conf->config($i->key, $agentnum) |js_string %> + ': ' + <% &{ $i->option_sub }( $conf->config($i->key, $agentnum) ) |js_string %>; diff --git a/httemplate/config/config.cgi b/httemplate/config/config.cgi index ce96bc162..cde48382a 100644 --- a/httemplate/config/config.cgi +++ b/httemplate/config/config.cgi @@ -131,7 +131,11 @@ Setting <% $key %> % } elsif ( $type eq 'select-sub' ) { - " <% $config_item->multiple ? 'MULTIPLE' : '' %>> + +% unless ( $config_item->multiple ) { +