- add new suspend and unsuspend export hooks (with null defaults)
authorivan <ivan>
Tue, 11 Jun 2002 03:25:03 +0000 (03:25 +0000)
committerivan <ivan>
Tue, 11 Jun 2002 03:25:03 +0000 (03:25 +0000)
- infostreet export: actually suspend/unsuspend at infostreet (closes: Bug#418)
- infostreet export: set some contact fields @ infostreet (Bug#419)

FS/FS/part_export.pm
FS/FS/part_export/infostreet.pm
FS/FS/svc_Common.pm
FS/FS/svc_acct.pm

index ae20146..bf60720 100644 (file)
@@ -414,6 +414,26 @@ sub export_delete {
   $self->_export_delete(@_);
 }
 
   $self->_export_delete(@_);
 }
 
+=item export_suspend
+
+=cut
+
+sub export_suspend {
+  my $self = shift;
+  $self->rebless;
+  $self->_export_suspend(@_);
+}
+
+=item export_unsuspend
+
+=cut
+
+sub export_unsuspend {
+  my $self = shift;
+  $self->rebless;
+  $self->_export_unsuspend(@_);
+}
+
 #fallbacks providing useful error messages intead of infinite loops
 sub _export_insert {
   my $self = shift;
 #fallbacks providing useful error messages intead of infinite loops
 sub _export_insert {
   my $self = shift;
@@ -430,6 +450,20 @@ sub _export_delete {
   return "_export_delete: unknown export type ". $self->exporttype;
 }
 
   return "_export_delete: unknown export type ". $self->exporttype;
 }
 
+#fallbacks providing null operations
+
+sub _export_suspend {
+  my $self = shift;
+  #warn "warning: _export_suspened unimplemented for". ref($self);
+  '';
+}
+
+sub _export_unsuspend {
+  my $self = shift;
+  #warn "warning: _export_unsuspend unimplemented for ". ref($self);
+  '';
+}
+
 =back
 
 =head1 SUBROUTINES
 =back
 
 =head1 SUBROUTINES
index 2ce5563..8bf227d 100644 (file)
@@ -1,16 +1,42 @@
 package FS::part_export::infostreet;
 
 package FS::part_export::infostreet;
 
-use vars qw(@ISA);
+use vars qw(@ISA %infostreet2cust_main);
 use FS::part_export;
 
 @ISA = qw(FS::part_export);
 
 use FS::part_export;
 
 @ISA = qw(FS::part_export);
 
+%infostreet2cust_main = (
+  'firstName'   => 'first',
+  'lastName'    => 'last',
+  'address1'    => 'address1',
+  'address2'    => 'address2',
+  'city'        => 'city',
+  'state'       => 'state',
+  'zipCode'     => 'zip',
+  'country'     => 'country',
+  'phoneNumber' => 'dayphone',
+);
+
 sub rebless { shift; }
 
 sub _export_insert {
   my( $self, $svc_acct ) = (shift, shift);
 sub rebless { shift; }
 
 sub _export_insert {
   my( $self, $svc_acct ) = (shift, shift);
-  $self->infostreet_queue( $svc_acct->svcnum,
+  my $cust_main = $svc_acct->cust_svc->cust_pkg->cust_main;
+  my $accountID = $self->infostreet_queue( $svc_acct->svcnum,
     'createUser', $svc_acct->username, $svc_acct->_password );
     'createUser', $svc_acct->username, $svc_acct->_password );
+  foreach my $infostreet_field ( keys %infostreet2cust_main ) {
+    my $error = $self->infostreet_queue( $svc_acct->svcnum,
+      'setContactField', $accountID, $infostreet_field,
+        $cust_main->getfield( $infostreet2cust_main{$infostreet_field} ) );
+    return $error if $error;
+  }
+
+  $self->infostreet_queue( $svc_acct->svcnum,
+    'setContactField', $accountID, 'email', $cust_main->invoicing_list )
+  #this one is kinda noment-specific
+  || $self->infostreet_queue( $svc_acct->svcnum,
+         'setContactField', $accountID, 'title', $cust_main->agent->agent );
+
 }
 
 sub _export_replace {
 }
 
 sub _export_replace {
@@ -28,6 +54,18 @@ sub _export_delete {
     'purgeAccount,releaseUsername', $svc_acct->username );
 }
 
     'purgeAccount,releaseUsername', $svc_acct->username );
 }
 
+sub _export_suspend {
+  my( $self, $svc_acct ) = (shift, shift);
+  $self->infostreet_queue( $svc_acct->svcnum,
+    'setStatus', $svc_acct->username, 'DISABLED' );
+}
+
+sub _export_unsuspend {
+  my( $self, $svc_acct ) = (shift, shift);
+  $self->infostreet_queue( $svc_acct->svcnum,
+    'setStatus', $svc_acct->username, 'ACTIVE' );
+}
+
 sub infostreet_queue {
   my( $self, $svcnum, $method ) = (shift, shift, shift);
   my $queue = new FS::queue {
 sub infostreet_queue {
   my( $self, $svcnum, $method ) = (shift, shift, shift);
   my $queue = new FS::queue {
@@ -68,8 +106,17 @@ sub infostreet_command { #subroutine, not method
   my %result = _infostreet_parse($result);
   die $result{error} unless $result{success};
 
   my %result = _infostreet_parse($result);
   die $result{error} unless $result{success};
 
+  $result->{data};
+
 }
 
 }
 
+#sub infostreet_command_byid { #subroutine, not method;
+#  my($url, $username, $password, $groupID, $method, @args ) = @_;
+#
+#  infostreet_command
+#
+#}
+
 sub _infostreet_parse { #subroutine, not method
   my $arg = shift;
   map {
 sub _infostreet_parse { #subroutine, not method
   my $arg = shift;
   map {
index c804242..cd278ef 100644 (file)
@@ -274,24 +274,92 @@ sub cust_svc {
 
 =item suspend
 
 
 =item suspend
 
+Runs export_suspend callbacks.
+
+=cut
+
+sub suspend {
+  my $self = shift;
+
+  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;
+
+  #new-style exports!
+  unless ( $noexport_hack ) {
+    foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
+      my $error = $part_export->export_suspend($self);
+      if ( $error ) {
+        $dbh->rollback if $oldAutoCommit;
+        return "error exporting to ". $part_export->exporttype.
+               " (transaction rolled back): $error";
+      }
+    }
+  }
+
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+  '';
+
+}
+
 =item unsuspend
 
 =item unsuspend
 
+Runs export_unsuspend callbacks.
+
+=cut
+
+sub unsuspend {
+  my $self = shift;
+
+  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;
+
+  #new-style exports!
+  unless ( $noexport_hack ) {
+    foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
+      my $error = $part_export->export_unsuspend($self);
+      if ( $error ) {
+        $dbh->rollback if $oldAutoCommit;
+        return "error exporting to ". $part_export->exporttype.
+               " (transaction rolled back): $error";
+      }
+    }
+  }
+
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+  '';
+
+}
+
 =item cancel
 
 =item cancel
 
-Stubs - return false (no error) so derived classes don't need to define these
+Stub - returns false (no error) so derived classes don't need to define these
 methods.  Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
 
 =cut
 
 methods.  Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
 
 =cut
 
-sub suspend { ''; }
-sub unsuspend { ''; }
 sub cancel { ''; }
 
 =back
 
 =head1 VERSION
 
 sub cancel { ''; }
 
 =back
 
 =head1 VERSION
 
-$Id: svc_Common.pm,v 1.10 2002-06-10 02:52:37 ivan Exp $
+$Id: svc_Common.pm,v 1.11 2002-06-11 03:25:03 ivan Exp $
 
 =head1 BUGS
 
 
 =head1 BUGS
 
index e3589d8..f0b0abc 100644 (file)
@@ -433,10 +433,11 @@ sub suspend {
          ) {
     $hash{_password} = '*SUSPENDED* '.$hash{_password};
     my $new = new FS::svc_acct ( \%hash );
          ) {
     $hash{_password} = '*SUSPENDED* '.$hash{_password};
     my $new = new FS::svc_acct ( \%hash );
-    $new->replace($self);
-  } else {
-    ''; #no error (already suspended)
+    my $error = $new->replace($self);
+    return $error if $error;
   }
   }
+
+  $self->SUPER::suspend;
 }
 
 =item unsuspend
 }
 
 =item unsuspend
@@ -454,10 +455,11 @@ sub unsuspend {
   if ( $hash{_password} =~ /^\*SUSPENDED\* (.*)$/ ) {
     $hash{_password} = $1;
     my $new = new FS::svc_acct ( \%hash );
   if ( $hash{_password} =~ /^\*SUSPENDED\* (.*)$/ ) {
     $hash{_password} = $1;
     my $new = new FS::svc_acct ( \%hash );
-    $new->replace($self);
-  } else {
-    ''; #no error (already unsuspended)
+    my $error = $new->replace($self);
+    return $error if $error;
   }
   }
+
+  $self->SUPER::unsuspend;
 }
 
 =item cancel
 }
 
 =item cancel