+=cut
+
+my $rt_session;
+
+sub delete {
+ my $self = shift;
+
+ my $cust_pkg = $self->cust_pkg;
+ my $custnum = $cust_pkg->custnum if $cust_pkg;
+
+ 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;
+
+ # delete associated export_cust_svc
+ foreach my $export_cust_svc (
+ qsearch('export_cust_svc',{ 'svcnum' => $self->svcnum })
+ ) {
+ my $error = $export_cust_svc->delete;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ }
+
+ my $error = $self->SUPER::delete;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+
+ foreach my $part_svc_link ( $self->part_svc_link(
+ link_type => 'cust_svc_unprovision_cascade',
+ )
+ ) {
+ foreach my $cust_svc ( qsearch( 'cust_svc', {
+ 'pkgnum' => $self->pkgnum,
+ 'svcpart' => $part_svc_link->dst_svcpart,
+ })
+ ) {
+ my $error = $cust_svc->svc_x->delete;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ }
+
+ }
+
+ $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+
+ if ( $ticket_system eq 'RT_Internal' ) {
+ unless ( $rt_session ) {
+ FS::TicketSystem->init;
+ $rt_session = FS::TicketSystem->session;
+ }
+ my $links = RT::Links->new($rt_session->{CurrentUser});
+ my $svcnum = $self->svcnum;
+ $links->Limit(FIELD => 'Target',
+ VALUE => 'freeside://freeside/cust_svc/'.$svcnum);
+ while ( my $l = $links->Next ) {
+ my ($val, $msg);
+ if ( $custnum ) {
+ # re-link to point to the customer instead
+ ($val, $msg) =
+ $l->SetTarget('freeside://freeside/cust_main/'.$custnum);
+ } else {
+ # unlinked service
+ ($val, $msg) = $l->Delete;
+ }
+ # can't do anything useful on error
+ warn "error unlinking ticket $svcnum: $msg\n" if !$val;
+ }
+ }
+
+ '';
+
+}
+
+=item suspend
+
+Suspends the relevant service by calling the B<suspend> method of the associated
+FS::svc_XXX object (i.e. an FS::svc_acct object or FS::svc_domain object).
+
+If there is an error, returns the error, otherwise returns false.
+
+=cut
+
+sub suspend {
+ my( $self, %opt ) = @_;
+
+ $self->part_svc->svcdb =~ /^([\w\-]+)$/ or return 'Illegal part_svc.svcdb';
+ my $svcdb = $1;
+ require "FS/$svcdb.pm";
+
+ my $svc = qsearchs( $svcdb, { 'svcnum' => $self->svcnum } )
+ or return '';
+
+ my $error = $svc->suspend;
+ return $error if $error;
+
+ if ( $opt{labels_arryref} ) {
+ my( $label, $value ) = $self->label;
+ push @{ $opt{labels_arrayref} }, "$label: $value";
+ }
+
+ '';
+
+}
+