for prepaid packages, trigger export update of RADIUS Expiration attribute when cust_...
authorivan <ivan>
Fri, 11 Nov 2005 14:06:34 +0000 (14:06 +0000)
committerivan <ivan>
Fri, 11 Nov 2005 14:06:34 +0000 (14:06 +0000)
FS/FS/cust_pkg.pm
FS/FS/svc_acct.pm

index d93b6de..cb4f944 100644 (file)
@@ -264,6 +264,8 @@ suspend is normally updated by the suspend and unsuspend methods.
 cancel is normally updated by the cancel method (and also the order subroutine
 in some cases).
 
+Calls 
+
 =cut
 
 sub replace {
@@ -281,7 +283,51 @@ sub replace {
 
   local($disable_agentcheck) = 1 if $old->pkgpart == $new->pkgpart;
 
-  $new->SUPER::replace($old);
+  local $SIG{HUP} = 'IGNORE';
+  local $SIG{INT} = 'IGNORE';
+  local $SIG{QUIT} = 'IGNORE';
+  local $SIG{TERM} = 'IGNORE';
+  local $SIG{TSTP} = 'IGNORE';
+  local $SIG{PIPE} = 'IGNORE';
+
+  my $oldAutoCommit = $FS::UID::AutoCommit;
+  local $FS::UID::AutoCommit = 0;
+  my $dbh = dbh;
+
+  #save off and freeze RADIUS attributes for any associated svc_acct records
+  my @svc_acct = ();
+  if ( $old->part_pkg->is_prepaid || $new->part_pkg->is_prepaid ) {
+
+                #also check for specific exports?
+                # to avoid spurious modify export events
+    @svc_acct = map  { $_->svc_x }
+                grep { $_->part_svc->svcdb eq 'svc_acct' }
+                     $old->cust_svc;
+
+    $_->snapshot foreach @svc_acct;
+
+  }
+
+  my $error = $new->SUPER::replace($old);
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return $error;
+  }
+
+  #for prepaid packages,
+  #trigger export of new RADIUS Expiration attribute when cust_pkg.bill changes
+  foreach my $old_svc_acct ( @svc_acct ) {
+    my $new_svc_acct = new FS::svc_acct { $old_svc_acct->hash };
+    my $s_error = $new_svc_acct->replace($old_svc_acct);
+    if ( $s_error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return $s_error;
+    }
+  }
+
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+  '';
+
 }
 
 =item check
index a9cdfb3..c7aa946 100644 (file)
@@ -1021,6 +1021,9 @@ expected to change in the future.
 sub radius_reply { 
   my $self = shift;
 
+  return %{ $self->{'radius_reply'} }
+    if exists $self->{'radius_reply'};
+
   my %reply =
     map {
       /^(radius_(.*))$/;
@@ -1054,6 +1057,9 @@ expected to change in the future.
 sub radius_check {
   my $self = shift;
 
+  return %{ $self->{'radius_check'} }
+    if exists $self->{'radius_check'};
+
   my %check = 
     map {
       /^(rc_(.*))$/;
@@ -1074,6 +1080,41 @@ sub radius_check {
 
 }
 
+=item snapshot
+
+This method instructs the object to "snapshot" or freeze RADIUS check and
+reply attributes to the current values.
+
+=cut
+
+#bah, my english is too broken this morning
+#Of note is the "Expiration" attribute, which, for accounts in prepaid packages, is typically defined on-the-fly as the associated packages cust_pkg.bill.  (This is used by
+#the FS::cust_pkg's replace method to trigger the correct export updates when
+#package dates change)
+
+sub snapshot {
+  my $self = shift;
+
+  $self->{$_} = { $self->$_() }
+    foreach qw( radius_reply radius_check );
+
+}
+
+=item forget_snapshot
+
+This methos instructs the object to forget any previously snapshotted
+RADIUS check and reply attributes.
+
+=cut
+
+sub forget_snapshot {
+  my $self = shift;
+
+  delete $self->{$_}
+    foreach qw( radius_reply radius_check );
+
+}
+
 =item domain
 
 Returns the domain associated with this account.