summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2013-06-12 02:55:14 -0700
committerIvan Kohler <ivan@freeside.biz>2013-06-12 02:55:14 -0700
commit20c649e7838f9448e53e0ba1c8e49820f031fc3e (patch)
treec01458ae4b9ff20db15b01fdb17bd312ab45c731 /FS
parent160885729789305b2138d3474c07c953c43234f7 (diff)
export pkg_change hook, RT#22596
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/cust_pkg.pm42
-rw-r--r--FS/FS/cust_svc.pm11
2 files changed, 50 insertions, 3 deletions
diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index 0980577..1c9d8e1 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -581,9 +581,12 @@ sub replace {
}
- my $error = $new->SUPER::replace($old,
- $options->{options} ? $options->{options} : ()
- );
+ my $error = $new->export_pkg_change($old)
+ || $new->SUPER::replace( $old,
+ $options->{options}
+ ? $options->{options}
+ : ()
+ );
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
@@ -3308,6 +3311,39 @@ sub reexport {
}
+=item export_pkg_change OLD_CUST_PKG
+
+Calls the "pkg_change" export action for all services attached to this package.
+
+=cut
+
+sub export_pkg_change {
+ my( $self, $old ) = ( shift, 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;
+
+ foreach my $svc_x ( map $_->svc_x, $self->cust_svc ) {
+ my $error = $svc_x->export('pkg_change', $self, $old);
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ }
+
+ $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+ '';
+
+}
+
=item insert_reason
Associates this package with a (suspension or cancellation) reason (see
diff --git a/FS/FS/cust_svc.pm b/FS/FS/cust_svc.pm
index 94f04e9..6aa254f 100644
--- a/FS/FS/cust_svc.pm
+++ b/FS/FS/cust_svc.pm
@@ -295,6 +295,17 @@ sub replace {
# }
# }
+ #trigger a pkg_change export on pkgnum changes
+ if ( $new->pkgnum != $old->pkgnum ) {
+ my $error = $new->svc_x->export('pkg_change', $new->cust_pkg,
+ $old->cust_pkg,
+ );
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error if $error;
+ }
+ }
+
#my $error = $new->SUPER::replace($old, @_);
my $error = $new->SUPER::replace($old);
if ( $error ) {