X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fsvc_Common.pm;h=2e236ee2e107dfa38450584f75b41c8f0a0a1951;hb=0702b1c193ecc9bd5a8a34f48b537b13b7ae6c20;hp=87b6097aaf11bf0dfac6e7e9e6233e397781dfa3;hpb=a930f5bc47c9c2de989074f1570beaa8f116bd22;p=freeside.git diff --git a/FS/FS/svc_Common.pm b/FS/FS/svc_Common.pm index 87b6097aa..2e236ee2e 100644 --- a/FS/FS/svc_Common.pm +++ b/FS/FS/svc_Common.pm @@ -28,7 +28,7 @@ inherit from, i.e. FS::svc_acct. FS::svc_Common inherits from FS::Record. =over 4 -=item insert [ JOBNUM_ARRAYREF ] +=item insert [ JOBNUM_ARRAYREF [ OBJECTS_ARRAYREF ] ] Adds this record to the database. If there is an error, returns the error, otherwise returns false. @@ -39,11 +39,16 @@ defined. An FS::cust_svc record will be created and inserted. If an arrayref is passed as parameter, the Bs of any export jobs will be added to the array. +If an arrayref of FS::tablename objects (for example, FS::acct_snarf objects) +is passed as the optional second parameter, they will have their svcnum fields +set and will be inserted after this record, but before any exports are run. + =cut sub insert { my $self = shift; local $FS::queue::jobnums = shift if @_; + my $objects = scalar(@_) ? shift : []; my $error; local $SIG{HUP} = 'IGNORE'; @@ -61,10 +66,12 @@ sub insert { return $error if $error; my $svcnum = $self->svcnum; - my $cust_svc; - unless ( $svcnum ) { + my $cust_svc = $svcnum ? qsearchs('cust_svc',{'svcnum'=>$self->svcnum}) : ''; + #unless ( $svcnum ) { + if ( !$svcnum or !$cust_svc ) { $cust_svc = new FS::cust_svc ( { #hua?# 'svcnum' => $svcnum, + 'svcnum' => $self->svcnum, 'pkgnum' => $self->pkgnum, 'svcpart' => $self->svcpart, } ); @@ -75,7 +82,7 @@ sub insert { } $svcnum = $self->svcnum($cust_svc->svcnum); } else { - $cust_svc = qsearchs('cust_svc',{'svcnum'=>$self->svcnum}); + #$cust_svc = qsearchs('cust_svc',{'svcnum'=>$self->svcnum}); unless ( $cust_svc ) { $dbh->rollback if $oldAutoCommit; return "no cust_svc record found for svcnum ". $self->svcnum; @@ -90,6 +97,15 @@ sub insert { return $error; } + foreach my $object ( @$objects ) { + $object->svcnum($self->svcnum); + $error = $object->insert; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + #new-style exports! unless ( $noexport_hack ) { foreach my $part_export ( $self->cust_svc->part_svc->part_export ) { @@ -242,7 +258,7 @@ sub setx { #get part_svc my $svcpart; - if ( $self->svcnum ) { + if ( $self->svcnum && qsearchs('cust_svc', {'svcnum'=>$self->svcnum}) ) { my $cust_svc = $self->cust_svc; return "Unknown svcnum" unless $cust_svc; $svcpart = $cust_svc->svcpart; @@ -364,7 +380,7 @@ sub cancel { ''; } =head1 VERSION -$Id: svc_Common.pm,v 1.12 2002-06-14 11:22:53 ivan Exp $ +$Id: svc_Common.pm,v 1.12.4.4 2003-11-12 12:29:55 ivan Exp $ =head1 BUGS