[freeside-commits] branch FREESIDE_3_BRANCH updated. bbbe62f2012ba5c384fd6bf8b98833aca79b8afc

Ivan ivan at 420.am
Wed Jun 12 02:55:23 PDT 2013


The branch, FREESIDE_3_BRANCH has been updated
       via  bbbe62f2012ba5c384fd6bf8b98833aca79b8afc (commit)
      from  31b49b580727c2c9dca516b9ccbb67b10e6d0fcf (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit bbbe62f2012ba5c384fd6bf8b98833aca79b8afc
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Wed Jun 12 02:55:20 2013 -0700

    export pkg_change hook, RT#22596

diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index f770974..a1d6556 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;
@@ -3274,6 +3277,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 ) {

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/cust_pkg.pm |   42 +++++++++++++++++++++++++++++++++++++++---
 FS/FS/cust_svc.pm |   11 +++++++++++
 2 files changed, 50 insertions(+), 3 deletions(-)




More information about the freeside-commits mailing list