implement fallback suspension code
[freeside.git] / FS / FS / svc_Common.pm
index 524e550..a154f3f 100644 (file)
@@ -49,8 +49,10 @@ sub virtual_fields {
 
   if ($self->svcpart) { # Case 1
     $svcpart = $self->svcpart;
-  } elsif (my $cust_svc = $self->cust_svc) { # Case 2
-    $svcpart = $cust_svc->svcpart;
+  } elsif ( $self->svcnum
+            && qsearchs('cust_svc',{'svcnum'=>$self->svcnum} )
+          ) { #Case 2
+    $svcpart = $self->cust_svc->svcpart;
   } else { # Case 3
     $svcpart = '';
   }
@@ -80,7 +82,7 @@ sub check {
   $self->SUPER::check;
 }
 
-=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.
@@ -91,11 +93,16 @@ defined.  An FS::cust_svc record will be created and inserted.
 If an arrayref is passed as parameter, the B<jobnum>s 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';
@@ -113,10 +120,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,
     } );
@@ -127,7 +136,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;
@@ -142,6 +151,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 ) {
@@ -294,7 +312,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;
@@ -412,11 +430,31 @@ methods.  Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
 
 sub cancel { ''; }
 
-=back
+=item clone_suspended
+
+Constructor used by FS::part_export::_export_suspend fallback.  Stub returning
+same object for svc_ classes which don't implement a suspension fallback
+(everything except svc_acct at the moment).  Document better.
 
-=head1 VERSION
+=cut
+
+sub clone_suspended {
+  shift;
+}
+
+=item clone_kludge_unsuspend 
+
+Constructor used by FS::part_export::_export_unsuspend fallback.  Stub returning
+same object for svc_ classes which don't implement a suspension fallback
+(everything except svc_acct at the moment).  Document better.
 
-$Id: svc_Common.pm,v 1.13 2003-08-05 00:20:47 khoff Exp $
+=cut
+
+sub clone_kludge_unsuspend {
+  shift;
+}
+
+=back
 
 =head1 BUGS