enable CardFortress in test database, #71513
[freeside.git] / FS / FS / mailinglistmember.pm
index ca73b88..5986bba 100644 (file)
@@ -1,11 +1,9 @@
 package FS::mailinglistmember;
+use base qw(FS::Record);
 
 use strict;
-use base qw( FS::Record );
-use FS::Record qw( qsearchs ); # qsearch );
-use FS::mailinglist;
-use FS::svc_acct;
-use FS::contact_email;
+use Scalar::Util qw( blessed );
+use FS::Record qw( dbh ); # qsearch qsearchs dbh );
 
 =head1 NAME
 
@@ -82,7 +80,30 @@ otherwise returns false.
 
 =cut
 
-# the insert method can be inherited from FS::Record
+sub insert {
+  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;
+
+  my $error =    $self->SUPER::insert
+              || $self->export('mailinglistmember_insert');
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return $error;
+  }
+
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+  '';
+}
 
 =item delete
 
@@ -90,7 +111,30 @@ Delete this record from the database.
 
 =cut
 
-# the delete method can be inherited from FS::Record
+sub delete {
+  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;
+
+  my $error =    $self->SUPER::delete
+              || $self->export('mailinglistmember_delete');
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return $error;
+  }
+
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+  '';
+}
 
 =item replace OLD_RECORD
 
@@ -99,7 +143,34 @@ returns the error, otherwise returns false.
 
 =cut
 
-# the replace method can be inherited from FS::Record
+sub replace {
+  my $new = shift;
+
+  my $old = ( blessed($_[0]) && $_[0]->isa('FS::Record') )
+              ? shift
+              : $new->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;
+
+  my $error =    $new->SUPER::replace($old)
+              || $new->export('mailinglistmember_replace', $old);
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return $error;
+  }
+
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+  '';
+}
 
 =item check
 
@@ -129,11 +200,25 @@ sub check {
 
 =item mailinglist
 
+=item email_address
+
 =cut
 
-sub mailinglist {
+sub email_address {
   my $self = shift;
-  qsearchs('mailinglist', { 'listnum' => $self->listnum } );
+  #XXX svcnum, contactemailnum
+  $self->email;
+}
+
+=item export
+
+=cut
+
+sub export {
+  my( $self, $method ) = ( shift, shift );
+  my $svc_mailinglist = $self->mailinglist->svc_mailinglist
+    or return '';
+  $svc_mailinglist->export($method, $self, @_);
 }
 
 =back