X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_pkg_link.pm;h=ce071ef17b358f1d71f5be4440d18bc199cc2ecc;hb=eb6536b41456955fc425dba2e156a996e8fe2837;hp=aee0131d233b429201dcfe850ba98e690dd2804e;hpb=6a0ca9cada89d08efe9d9e7a9e2fa4365a0a1b6a;p=freeside.git diff --git a/FS/FS/part_pkg_link.pm b/FS/FS/part_pkg_link.pm index aee0131d2..ce071ef17 100644 --- a/FS/FS/part_pkg_link.pm +++ b/FS/FS/part_pkg_link.pm @@ -130,6 +130,7 @@ sub insert { return $error if $error; } + $dbh->commit if $oldAutoCommit; return; } @@ -166,10 +167,18 @@ sub delete { $dbh->rollback if $oldAutoCommit; return $error; } - $dbh->commit; + $dbh->commit if $oldAutoCommit; return; } +=item remove_linked + +Removes any supplemental packages that were created by this link, by canceling +them and setting their pkglinknum to null. This should be done in preparation +for removing the link itself. + +=cut + sub remove_linked { my $self = shift; my $pkglinknum = $self->pkglinknum; @@ -180,23 +189,11 @@ sub remove_linked { warn "expiring ".scalar(@pkgs). " linked packages from part_pkg_link #$pkglinknum\n"; - my $reason = qsearchs('reason', { reason => $cancel_reason_text }); - if (!$reason) { - # upgrade/FS::Setup created this one automatically - my $reason_type = qsearchs('reason_type', - { type => $cancel_reason_type } - ) or die "default cancel reason type does not exist"; - - $reason = FS::reason->new({ - reason_type => $reason_type->typenum, - reason => $cancel_reason_text, - disabled => 'Y', - }); - $error = $reason->insert; - if ( $error ) { - return "$error (creating package cancel reason)"; - } - } + my $reason = FS::reason->new_or_existing( + class => 'C', + type => $cancel_reason_type, + reason => $cancel_reason_text + ); foreach my $pkg (@pkgs) { $pkg->set('pkglinknum' => '');