- 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);
- if ($error) {
- $dbh->rollback if $oldAutoCommit;
- return $error;
- }
-
- my $old_svc_acct = $old->srcsvc_acct;
- my $old_username = $old_svc_acct->username;
- my $old_domain = $old_svc_acct->domain;
- my $destination;
- if ($old->dstsvc) {
- $destination = $old->dstsvc_acct->email;
- } else {
- $destination = $old->dst;
- }
- foreach my $vpopmailmachine ( @vpopmailmachines ) {
- my($machine, $vpopdir, $vpopuid, $vpopgid) =
- split(/\s+/, $vpopmailmachine);
- my $queue = new FS::queue {
- 'svcnum' => $new->svcnum,
- 'job' => 'Net::SSH::ssh_cmd',
- };
- # should be neater
- my $error = $queue->insert("root\@$machine",
- "sed -e '/^$destination/d' " .
- "< $vpopdir/domains/$old_domain/$old_username/.qmail" .
- "> $vpopdir/domains/$old_domain/$old_username/.qmail.temp; " .
- "mv $vpopdir/domains/$old_domain/$old_username/.qmail.temp " .
- "$vpopdir/domains/$old_domain/$old_username/.qmail; " .
- "chown $vpopuid.$vpopgid " .
- "$vpopdir/domains/$old_domain/$old_username/.qmail;"
- )
- unless $nossh_hack;
-
- if ( $error ) {
- $dbh->rollback if $oldAutoCommit;
- return "queueing job (transaction rolled back): $error";
- }
- }
-
- #false laziness with stuff in insert, should subroutine
- my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $new->srcsvc } );
- my $username = $svc_acct->username;
- my $domain = $svc_acct->domain;
- if ($new->dstsvc) {
- $destination = $new->dstsvc_acct->email;
- } else {
- $destination = $new->dst;
- }
-
- foreach my $vpopmailmachine ( @vpopmailmachines ) {
- my($machine, $vpopdir, $vpopuid, $vpopgid) = split(/\s+/, $vpopmailmachine);
- my $queue = new FS::queue {
- 'svcnum' => $new->svcnum,
- 'job' => 'Net::SSH::ssh_cmd',
- };
- # should be neater
- my $error = $queue->insert("root\@$machine","[ -d $vpopdir/domains/$domain/$username ] && { echo \"$destination\" >> $vpopdir/domains/$domain/$username/.qmail; chown $vpopuid:$vpopgid $vpopdir/domains/$domain/$username/.qmail; }")
- unless $nossh_hack;
- if ( $error ) {
- $dbh->rollback if $oldAutoCommit;
- return "queueing job (transaction rolled back): $error";
- }
- }
- #end subroutinable bits
-
- $dbh->commit or die $dbh->errstr if $oldAutoCommit;
- '';