summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FS/FS/Mason.pm1
-rw-r--r--FS/FS/Schema.pm3
-rw-r--r--FS/FS/svc_Common.pm54
-rw-r--r--FS/FS/svc_export_machine.pm19
-rwxr-xr-xhttemplate/edit/process/svc_acct.cgi27
-rwxr-xr-xhttemplate/edit/svc_acct.cgi6
-rw-r--r--httemplate/elements/tr-svc_export_machine.html37
-rw-r--r--httemplate/view/elements/tr-svc_export_machine.html27
-rw-r--r--httemplate/view/svc_acct/basics.html5
9 files changed, 161 insertions, 18 deletions
diff --git a/FS/FS/Mason.pm b/FS/FS/Mason.pm
index 39c7dfd..11af25e 100644
--- a/FS/FS/Mason.pm
+++ b/FS/FS/Mason.pm
@@ -325,6 +325,7 @@ if ( -e $addl_handler_use_file ) {
use FS::cust_tax_exempt_pkg_void;
use FS::cust_bill_pkg_discount_void;
use FS::agent_pkg_class;
+ use FS::svc_export_machine;
# Sammath Naur
if ( $FS::Mason::addl_handler_use ) {
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index 6e3956a..7be8c66 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -1894,10 +1894,11 @@ sub tables_hashref {
'columns' => [
'svcexportmachinenum', 'serial', '', '', '', '',
'svcnum', 'int', '', '', '', '',
+ 'exportnum', 'int', '', '', '', '',
'machinenum', 'int', '', '', '', '',
],
'primary_key' => 'svcexportmachinenum',
- 'unique' => [],
+ 'unique' => [ ['svcnum', 'exportnum'] ],
'index' => [],
},
diff --git a/FS/FS/svc_Common.pm b/FS/FS/svc_Common.pm
index a6daf44..7aede54 100644
--- a/FS/FS/svc_Common.pm
+++ b/FS/FS/svc_Common.pm
@@ -200,12 +200,13 @@ I<depend_jobnum>.
If I<jobnum> is set to an array reference, the jobnums of any export jobs will
be added to the referenced array.
-If I<child_objects> is set to an array reference of FS::tablename objects (for
-example, FS::acct_snarf objects), they will have their svcnum field set and
-will be inserted after this record, but before any exports are run. Each
-element of the array can also optionally be a two-element array reference
-containing the child object and the name of an alternate field to be filled in
-with the newly-inserted svcnum, for example C<[ $svc_forward, 'srcsvc' ]>
+If I<child_objects> is set to an array reference of FS::tablename objects
+(for example, FS::svc_export_machine or FS::acct_snarf objects), they
+will have their svcnum field set and will be inserted after this record,
+but before any exports are run. Each element of the array can also
+optionally be a two-element array reference containing the child object
+and the name of an alternate field to be filled in with the newly-inserted
+svcnum, for example C<[ $svc_forward, 'srcsvc' ]>
If I<depend_jobnum> is set (to a scalar jobnum or an array reference of
jobnums), all provisioning jobs will have a dependancy on the supplied
@@ -439,7 +440,16 @@ sub expire {
Replaces OLD_RECORD with this one. If there is an error, returns the error,
otherwise returns false.
-Currently available options are: I<export_args> and I<depend_jobnum>.
+Currently available options are: I<child_objects>, I<export_args> and
+I<depend_jobnum>.
+
+If I<child_objects> is set to an array reference of FS::tablename objects
+(for example, FS::svc_export_machine or FS::acct_snarf objects), they
+will have their svcnum field set and will be inserted or replaced after
+this record, but before any exports are run. Each element of the array
+can also optionally be a two-element array reference containing the
+child object and the name of an alternate field to be filled in with
+the newly-inserted svcnum, for example C<[ $svc_forward, 'srcsvc' ]>
If I<depend_jobnum> is set (to a scalar jobnum or an array reference of
jobnums), all provisioning jobs will have a dependancy on the supplied
@@ -462,6 +472,8 @@ sub replace {
? shift
: { @_ };
+ my $objects = $options->{'child_objects'} || [];
+
my @jobnums = ();
local $FS::queue::jobnums = \@jobnums;
warn "[$me] replace: set \$FS::queue::jobnums to $FS::queue::jobnums\n"
@@ -511,6 +523,34 @@ sub replace {
return $error;
}
+ foreach my $object ( @$objects ) {
+ my($field, $obj);
+ if ( ref($object) eq 'ARRAY' ) {
+ ($obj, $field) = @$object;
+ } else {
+ $obj = $object;
+ $field = 'svcnum';
+ }
+ $obj->$field($new->svcnum);
+
+ my $oldobj = qsearchs( $obj->table, {
+ $field => $new->svcnum,
+ map { $_ => $obj->$_ } $obj->_svc_child_partfields,
+ });
+
+ if ( $oldobj ) {
+ my $pkey = $oldobj->primary_key;
+ $obj->$pkey($oldobj->$pkey);
+ $obj->replace($oldobj);
+ } else {
+ $error = $obj->insert;
+ }
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ }
+
#new-style exports!
unless ( $noexport_hack ) {
diff --git a/FS/FS/svc_export_machine.pm b/FS/FS/svc_export_machine.pm
index 39629d8..10f7b68 100644
--- a/FS/FS/svc_export_machine.pm
+++ b/FS/FS/svc_export_machine.pm
@@ -2,10 +2,13 @@ package FS::svc_export_machine;
use strict;
use base qw( FS::Record );
-use FS::Record; # qw( qsearch qsearchs );
+use FS::Record qw( qsearchs ); #qsearch );
use FS::cust_svc;
+use FS::part_export;
use FS::part_export_machine;
+sub _svc_child_partfields { ('exportnum') };
+
=head1 NAME
FS::svc_export_machine - Object methods for svc_export_machine records
@@ -89,14 +92,24 @@ sub check {
my $error =
$self->ut_numbern('svcexportmachinenum')
- || $self->ut_foreign_key('svcnum', 'cust_svc', 'svcnum')
- || $self->ut_foreign_key('machinenum', 'part_export_machine', 'machinenum' )
+ || $self->ut_foreign_key('svcnum', 'cust_svc', 'svcnum' )
+ || $self->ut_foreign_key('exportnum', 'part_export', 'exportnum' )
+ || $self->ut_foreign_key('machinenum', 'part_export_machine', 'machinenum')
;
return $error if $error;
$self->SUPER::check;
}
+=item part_export_machine
+
+=cut
+
+sub part_export_machine {
+ my $self = shift;
+ qsearchs('part_export_machine', { 'machinenum' => $self->machinenum } );
+}
+
=back
=head1 BUGS
diff --git a/httemplate/edit/process/svc_acct.cgi b/httemplate/edit/process/svc_acct.cgi
index a7d5136..41aca65 100755
--- a/httemplate/edit/process/svc_acct.cgi
+++ b/httemplate/edit/process/svc_acct.cgi
@@ -56,13 +56,14 @@ my $new = new FS::svc_acct ( \%hash );
my $error = '';
+my $part_svc = $svcnum ?
+ $old->part_svc :
+ qsearchs( 'part_svc',
+ { 'svcpart' => $cgi->param('svcpart') }
+ );
+
# google captcha auth
if ( $cgi->param('captcha_response') ) {
- my $part_svc = $svcnum ?
- $old->part_svc :
- qsearchs( 'part_svc',
- { 'svcpart' => $cgi->param('svcpart') }
- );
my ($export) = $part_svc->part_export('acct_google');
if ( $export and
! $export->captcha_auth($cgi->param('captcha_response')) ) {
@@ -79,6 +80,18 @@ if ( $cgi->param('clear_password') eq '*HIDDEN*'
}
if ( ! $error ) {
+
+ my $export_info = FS::part_export::export_info();
+
+ my @svc_export_machine =
+ map FS::svc_export_machine->new({
+ 'svcnum' => $svcnum,
+ 'exportnum' => $_->exportnum,
+ 'machinenum' => scalar($cgi->param('exportnum'.$_->exportnum.'machinenum')),
+ }),
+ grep { $_->machine eq '_SVC_MACHINE' }
+ $part_svc->part_export;
+
if ( $svcnum ) {
foreach ( grep { $old->$_ != $new->$_ }
qw( seconds upbytes downbytes totalbytes )
@@ -92,9 +105,9 @@ if ( ! $error ) {
$error ||= $new->set_usage(\%hash); #unoverlimit and trigger radius changes
last; #once is enough
}
- $error ||= $new->replace($old);
+ $error ||= $new->replace($old, 'child_objects'=>\@svc_export_machine);
} else {
- $error ||= $new->insert;
+ $error ||= $new->insert('child_objects'=>\@svc_export_machine);
$svcnum = $new->svcnum;
}
}
diff --git a/httemplate/edit/svc_acct.cgi b/httemplate/edit/svc_acct.cgi
index 38567ef..142c111 100755
--- a/httemplate/edit/svc_acct.cgi
+++ b/httemplate/edit/svc_acct.cgi
@@ -173,6 +173,12 @@ function randomPass() {
<INPUT TYPE="hidden" NAME="sectornum" VALUE="<% $svc_acct->sectornum %>">
%}
+<& /elements/tr-svc_export_machine.html,
+ 'svc' => $svc_acct,
+ 'part_svc' => $part_svc,
+ 'cgi' => $cgi,
+&>
+
% #uid/gid
% foreach my $xid (qw( uid gid )) {
%
diff --git a/httemplate/elements/tr-svc_export_machine.html b/httemplate/elements/tr-svc_export_machine.html
new file mode 100644
index 0000000..92b6ac1
--- /dev/null
+++ b/httemplate/elements/tr-svc_export_machine.html
@@ -0,0 +1,37 @@
+% foreach my $part_export (@part_export) {
+% my $label = ( $part_export->exportname
+% ? $part_export->exportname
+% : $part_export->label
+% ).
+% ' hostname';
+%
+% my $element = 'exportnum'. $part_export->exportnum. 'machinenum';
+% my $machinenum = $opt{cgi}->param($element);
+% if ( ! $machinenum && $opt{svc}->svcnum ) {
+% my $svc_export_machine = qsearchs('svc_export_machine', {
+% 'svcnum' => $opt{svc}->svcnum,
+% 'exportnum' => $part_export->exportnum,
+% });
+% $machinenum = $svc_export_machine->machinenum if $svc_export_machine;
+% }
+
+ <& /elements/tr-select-table.html,
+ 'label' => $label,
+ 'element_name' => 'exportnum'. $part_export->exportnum. 'machinenum',
+ 'table' => 'part_export_machine',
+ 'name_col' => 'machine',
+ 'hashref' => { 'exportnum' => $part_export->exportnum,
+ 'disabled' => '',
+ },
+ 'curr_value' => $machinenum,
+ 'empty_label' => 'Select export hostname',
+ &>
+% }
+<%init>
+
+my %opt = @_;
+
+my @part_export = grep { $_->machine eq '_SVC_MACHINE' }
+ $opt{part_svc}->part_export;
+
+</%init>
diff --git a/httemplate/view/elements/tr-svc_export_machine.html b/httemplate/view/elements/tr-svc_export_machine.html
new file mode 100644
index 0000000..1ba8d74
--- /dev/null
+++ b/httemplate/view/elements/tr-svc_export_machine.html
@@ -0,0 +1,27 @@
+% foreach my $part_export (@part_export) {
+% my $label = ( $part_export->exportname
+% ? $part_export->exportname
+% : $part_export->label
+% ).
+% ' hostname';
+%
+% my $svc_export_machine = qsearchs('svc_export_machine', {
+% 'svcnum' => $opt{svc}->svcnum,
+% 'exportnum' => $part_export->exportnum,
+% });
+
+ <& tr.html,
+ 'label' => $label,
+ 'value' => $svc_export_machine
+ ? $svc_export_machine->part_export_machine->machine
+ : '',
+ &>
+% }
+<%init>
+
+my %opt = @_;
+
+my @part_export = grep { $_->machine eq '_SVC_MACHINE' }
+ $opt{part_svc}->part_export;
+
+</%init>
diff --git a/httemplate/view/svc_acct/basics.html b/httemplate/view/svc_acct/basics.html
index bcd8469..1cdf776 100644
--- a/httemplate/view/svc_acct/basics.html
+++ b/httemplate/view/svc_acct/basics.html
@@ -56,6 +56,11 @@
&>
% }
+<& /view/elements/tr-svc_export_machine.html,
+ 'svc' => $svc_acct,
+ 'part_svc' => $part_svc,
+&>
+
% if ($svc_acct->uid ne '') {
<& /view/elements/tr.html, label=>mt('UID'), value=>$svc_acct->uid &>
% }